Morning,
Here's my problem:
I have a field (ResFileLocation) on a form (frmResolution) that inserts a record-specific value (record ID, date stamp, etc) through vba when it has gained focus.
To help clarify, here is the basic code I am looking at: - Private Sub ResFileLocation_GotFocus()
-
Me!ResFileLocation = "Forms![frmResolution]!NoticeID & "R_" & Left(Date, 2) & Mid(Date, 4, 2) & Right(Date, 4)
-
End Sub
However, this information should not be edited after it is inserted (by the user or the system) because it displays the file name of a PDF on a network drive.
So I tried setting the field Locked property to True after the GotFocus event, but the GotFocus event can still occur (i.e. the user can't edit, but the system still can); code below. - Private Sub ResFileLocation_GotFocus()
-
Me!ResFileLocation = "Forms![frmResolution]!NoticeID & "R_" & Left(Date, 2) & Mid(Date, 4, 2) & Right(Date, 4)
-
Me!ResFileLocation.Locked = True
-
End Sub
Changing the Enabled property to False is out because I want the user to be able to select and copy the text for pasting in a browser.
So, is there a way to let the GotFocus event run only once, locking the text after that occurence?
Thank you for any advice or help!
martin
5 2212
In the On_Current event of the form try writing something like; - If IsNull(Me!ResFileLocation) then
-
Me!ResFileLocation.Locked = False
-
Else
-
Me!ResFileLocation.Locked = True
-
End If
This should allow editing until the record has been saved.
If you wanted to force a 'save' immediately after ResFileLocation has been populated by your On-Focus event I would change YOUR line 3 to - DoCmd.RunCommand accCmdSaveRecord
I'm not sure I like using the OnFocus event to add data, but hey!
Hope this helps
S7
Morning,
Here's my problem:
I have a field (ResFileLocation) on a form (frmResolution) that inserts a record-specific value (record ID, date stamp, etc) through vba when it has gained focus.
To help clarify, here is the basic code I am looking at: - Private Sub ResFileLocation_GotFocus()
-
Me!ResFileLocation = "Forms![frmResolution]!NoticeID & "R_" & Left(Date, 2) & Mid(Date, 4, 2) & Right(Date, 4)
-
End Sub
However, this information should not be edited after it is inserted (by the user or the system) because it displays the file name of a PDF on a network drive.
So I tried setting the field Locked property to True after the GotFocus event, but the GotFocus event can still occur (i.e. the user can't edit, but the system still can); code below. - Private Sub ResFileLocation_GotFocus()
-
Me!ResFileLocation = "Forms![frmResolution]!NoticeID & "R_" & Left(Date, 2) & Mid(Date, 4, 2) & Right(Date, 4)
-
Me!ResFileLocation.Locked = True
-
End Sub
Changing the Enabled property to False is out because I want the user to be able to select and copy the text for pasting in a browser.
So, is there a way to let the GotFocus event run only once, locking the text after that occurence?
Thank you for any advice or help!
martin
Check to see if it is locked when it gets focus. If it isn't, do your stuff - else move to next control. -
Private Sub ResFileLocation_GotFocus()
-
If Me!ResFileLocation.Locked = False Then
-
Me!ResFileLocation = "Forms![frmResolution]!NoticeID & "R_" & Left(Date, 2) & Mid(Date, 4, 2) & Right(Date, 4)
-
Me!ResFileLocation.Locked = True
-
Else
-
Me!YourNextControl.SetFocus
-
End Sub
-
Just a thought - What if there is an "Oops, I screwed up by the end-user?"
Since this control's value is set with code should it "ever" get focus? You don't need to SetFocus in order to set the value. I would trigger it to set the value on the AfterUpdate event of the first control the user enters a value. Set autotab to No so it doesn't get focus on OnCurrent or when user tabs through controls.
Hi Jax
I follow your code and see how it works as a Data Entry system. Once ResFileLocation is visited it will be populated and locked WHILE ON THAT RECORD, but I don't understand how on future times the record is viewed (Browsed) that ResFileLocation will be Locked ?
I agree wholly with your last paragraph; this field should be populated as soon after the record is created as possible and not when the cursor happens to move there. Should it be editable at all ? I am assuming that [frmResolution] will definitely be open and NoticeID will have valid values.
Martin
I am not sure what will result by formulating the date code as you do. Would not Format(Date,"DDMMYYY") or Format(Date,"MMDDYYYY") if you prefer, be better? e.g. - Me!ResFileLocation = "Forms![frmResolution]!NoticeID & "R_" & Format(Date,"MMDDYYYY")
S7
Thank you both for your advice and suggestions. With these ideas I developed an alternative solution that fulfills all of the requirements.
First, yes frmResolution will be open. On this form, I locked the ResFileLocation textbox. I also added a command button that opens another form, frmLocation. - Private Sub cmdLocation_Click()
-
On Error GoTo Err_cmdLocation_Click
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
stDocName = "frmLocation"
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
Exit_cmdLocation_Click:
-
Exit Sub
-
Err_cmdLocation_Click:
-
MsgBox Err.Description
-
Resume Exit_cmdLocation_Click
-
End Sub
On frmLocation, I have four controls (3 textboxes and 1 command button).
txtExisting
txtFileLocation
txtFileName
cmdOK
txtExisting is locked and displays the data currently held in ResFileLocation on frmResolution - (=[Forms]![frmResolution]![ResFileLocation])
txtFileLocation is disabled but includes as a default the drive hierarchy on the network (will not change).
txtFileName includes as a default the name I was trying to include in the previous posts (with the date adjusted per S7's recommendation - thanks!). This textbox is unlocked and enabled so that the user can edit if necessary.
cmdOK saves txtFileLocation and txtFileName in ResFileLocation on frmResolution, then closes frmLocation. - Option Compare Database
-
Option Explicit
-
-
Private Sub cmdOK_Click()
-
Forms![frmResolution]!ResFileLocation = Me!txtLocation & Me!txtFileName
-
DoCmd.Close acForm, "frmLocation"
-
-
End Sub
-
-
Private Sub Form_Open(Cancel As Integer)
-
Me!txtLocation = "\\network\resolution\"
-
Me!txtFileName = Forms![frmResolution]!ClientID & "_NID" & Forms![frmResolution]!NoticeID & "R_" & Format(Date, "MMDDYYYY")
-
End Sub
This way, the user doesn't need to know the exact file path where the associated file will be saved. The user can also manually edit/update the location if needed. Thank you for your help!
One last thing: I'm thinking it might be a good idea to have a message box pop up when the user selects cmdOK on frmLocation asking if sure of making change (yes, no option). Can anyone point me to a good reference on devising these through vba? I've never used them before.
martin
One last thing: I'm thinking it might be a good idea to have a message box pop up when the user selects cmdOK on frmLocation asking if sure of making change (yes, no option). Can anyone point me to a good reference on devising these through vba? I've never used them before.
martin
Hi Martin
I'm glad we managed to help resolve your problem. It sounds as though you now have something more robust than relying on a On_Focus event.
I'm sorry about the delay in seeing this Message Box issue as I have been away for a week. As a general point it would have been better to raise it as a seperate thread, then other people would have seen it as a 'fresh' issue and would have responded by now.
The best advice I can give is to read the Access/VBA 'Help' topic and Example on this one because it is covered very well and there is no point repeating it here.
If any specific issues arise then raise them as new queries.
S7
Sign in to post your reply or Sign up for a free account.
Similar topics
by: TC |
last post by:
Hello,
I am using the script below to open a new window and once opened, redirect to that open window from the original window:
private void btnNewPDFWindow_Click(object sender,...
|
by: Darin |
last post by:
I have an html page (warehouse.htm) that has 2 frames (header.aspx and
checkstock.aspx). When warehouse.htm opens, and the other 2 aspx pages
load, I want the cursor to be sitting on the first...
|
by: Stefan De Schepper |
last post by:
Dear NG,
I created a gridlike usercontrol. When clicking on a cell a textbox (or
other control, depending on the cell's editortype) is shown. When some other
control gets the focus, the textbox...
|
by: Agnes |
last post by:
Same application, When use the dataset expor to EXCEL, work very well.
However, for some PC I will got the following error
"DOES NOT SUPPORT A COLLECTION.(EXCEPTION FROM HRESULT :...
|
by: Robert Jones |
last post by:
If my application doesn't have focus and someone clicks on the menu, the
menu click is "lost" as the form gets focus, and the user then has to click
on the menu a second time to actually activate...
|
by: woollymammoth |
last post by:
I can't assign a MS SQL Server table record value to a simple VB variable, should be an easy thing. Sample SQL Server table has the data in the record as a char(30) string, the column for that record...
|
by: ytterbius |
last post by:
Hello All,
I'm trying to become more Google-friendly, which involves adding the "rel = "nofollow"" attribute to many of my outgoing links.
I can't seem to find instructions on how to do this,...
|
by: freeskier |
last post by:
I have been using the following code to cycle through a subform and disable all textboxes on a form. If a textbox on the form has the focus when this is run I get error "can't disable a control when...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |