 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 3rd, 2004, 10:51 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
IF..Then..ELSE
Scenario: Bound Form. If the user initiates a change on the form in any field, I need them to update the Jake_Person_last_Updated field with their initials before they can close the form or move on to the next record.
This part (enclosed in the **)works fine and presents itself properly to the user
Private Sub Form_BeforeUpdate(Cancel As Integer)
************************************************** *************
Dim Msg, Style, Title, Response, Check 'Declare Variables.
Msg = "Do you want to save this record?" 'Message.
Style = vbYesNo + vbExclamation + vbDefaultButton2 'Define buttons.
Title = "Warning!" 'Define title of dialogue box.
Response = MsgBox(Msg, Style, Title)
************************************************** *************
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&
This part below works okay but only prompts the user twice, regardless if they enter their initial or not and then proceeds to save the record without the initials entered (have "required" prop in bound table also). How do I make sure the record doesn't update until the initials are entered in the field, no matter how many times it takes.? THANKS BPH
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&
If vbYes And Me.cboJake_Person_Last_Updated <> "" Then
'Update the timestamp on the record.
Forms!frm_Jake_Lifeinfo!txtDate_Last_Updated=Now ()
DoCmd.Save acForm, "frm_Jake_lifeinfo"
ElseIf Me.cboJake_Person_Last_Updated = "" Then
MsgBox "Please initial the 'LAST UPDATED BY' field.", vbOKOnly
Me.cboJake_Person_Last_Updated.SetFocus
ElseIf vbNo Then Me.Undo
End If
End Sub
|
|

February 3rd, 2004, 11:05 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
On your form, is cboJake_Person_Last_Updated a bound field? If not, this would cause the message box. However, if you have an app where users log in, instead of making them complete this field, why not update the records with CurrentUser()?
Beth M
|
|

February 3rd, 2004, 11:58 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Hi Beth. It is a bound field and the user group is small and they don't want to get into login id's.
Thanks, Brian
|
|

February 3rd, 2004, 12:13 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
|
quote:the user group is small and they don't want to get into login id's.
|
Then you could capture the network login, unless they are sharing the workstations while logged on.
|
|

February 3rd, 2004, 12:36 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Capturing the network login is a good idea. You can put something like this in the form's After Update event.
Code:
If Me.Dirty Then
'Assuming you read the login ID into strLoginID
Me.cboJake_Person_Last_Updated = strLoginID
'OR if you didn't read it in and need to ask....
strLoginID = InputBox("Data has been updated. What are your initials?", vbQuestion, "Data Updated")
End If
Remember to put in code to handle strLoginID is null or empty if you ask for it.
I don't like putting code in something like a Before Update event because how can you predict what's going to happen before someone updates it let alone if they're going to update something in the first place?
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

February 3rd, 2004, 12:38 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Oops... reverse the two lines of code I just wrote so that it asks for strLoginID before it assigns it to the combobox.
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

February 3rd, 2004, 01:04 PM
|
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Sounds like logins would expedite a solution. I'll try that route, see what the comfort level is.
Thanks!
|
|

February 3rd, 2004, 01:06 PM
|
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by SerranoG
Oops... reverse the two lines of code I just wrote so that it asks for strLoginID before it assigns it to the combobox. 
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
Thanks Greg!
|
|

February 3rd, 2004, 02:20 PM
|
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Well, I created the user ids and gave the admin account a password. Now I'm locked out, none of them work. I do have a backup, yet the users are showing up in the backup when I open. Strange. I'm going to find a way to do it with out users. Every Man Must know his limitations. ;)
|
|

February 4th, 2004, 11:40 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Another advantage of using the login id's is that if they are auto filled the field will have the actual id of the person logged in and not a set of initials the data entry person chooses. This is more secure.
Rand
|
|
 |