 |
| Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access 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
|
|
|
|

March 4th, 2004, 09:28 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
InputBox Misbehaving
Ah, to place blame on a mere little object. How sad! 
Anywho - This code runs when I open a form, and it present an inputbox before the form opens, which asks for the users initials. That's all good.
I have found though that the user can click OK or Cancel without entering initials and proceed right into the form. I would rather the inputbox close and the user not be allowed into the form.
What's good is that when the user is allowed into the form they can't proceed to enter data until the initials are entered.
I might not be able to have my cake and eat it too?
Thx, bph
Private Sub Form_Current()
Me.chkForeign1 = False
Me.chkForeign2 = False
Me.cboLake_Person_Last_Updated.SetFocus
On Error GoTo NoInitialsEntered
Dim varInitials As Variant
varInitials = InputBox("Please enter your initials.", "User Initials")
If IsNull(varInitials) Then
DoCmd.Close acForm, "add_frm_lake_pipeinfo", acSaveNo
Else
Me.cboLake_Person_Last_Updated.SetFocus
Me.cboLake_Person_Last_Updated.Text = (varInitials)
End If
NoInitialsEntered:
Select Case Err.Number
Case 2237
MsgBox "The initials entered are not valid"
Exit Sub
End Select
|
|

March 4th, 2004, 09:36 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
How about...
varInitials = Nz(Trim(InputBox("Please enter your initials.", "User Initials")),"")
If varInitials = "" Or varInitials = vbCancel Then
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

March 4th, 2004, 09:50 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
I had tried something similar to that and it still let them in. It just doesn't pay atttention to the fact that nothing was entered or the cancel was clicked. Maybe some code in another part of the form is messing it up.
thx, bph
|
|

March 4th, 2004, 10:07 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Try putting a simplier code on the form's ON OPEN event, not on the ON CURRENT event.
Code:
varInitials = Nz(Trim(InputBox("Please enter your initials.", "User Initials")),"")
If varInitials = "" Then
DoCmd.Close
Else
...
End If
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

March 4th, 2004, 10:07 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I use the following and it works fine:
Code:
If Len(strIDInput & vbnullstring) = 0 Then
MsgBox "My message for user and exits routine.", , "AppName"
Exit Sub
Else
Beth M
|
|

March 4th, 2004, 10:25 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
In VB I use IsEmpty() to test the result:
Code:
sResult = InputBox("Enter your initials", "User Data")
If IsEmpty(sResult) Then
'User clicked cancel
Else
If Len(sResult) = 0
'User okayed but did not enter anything
Else
'User entered a string
End If
End If
--
Joe
|
|

March 4th, 2004, 11:24 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Greg, Putting in the form On Open Event does the job except that I then get a "stutter" so to speak because the On Current Event fires and is looking for the initals as well. So I hit cancel, then I hit cancel again, then back to switchboard. Same when the user enters valid initials, the On Open asks, then the On Current event asks for the initials, and then the user gets into the form. I need the on current stuff to stay as is though.
Quote:
quote:Originally posted by SerranoG
Try putting a simplier code on the form's ON OPEN event, not on the ON CURRENT event.
Code:
varInitials = Nz(Trim(InputBox("Please enter your initials.", "User Initials")),"")
If varInitials = "" Then
DoCmd.Close
Else
...
End If
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|
|

March 4th, 2004, 11:32 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Oh, when I said put it on the ON OPEN event, I thought it implied that you must take it off the ON CURRENT event. You only need to capture a person's initials once after they open the form, not ask for every record. So remove the inputbox code from the ON CURRENT.
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

March 4th, 2004, 11:49 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Thanks Greg. That would be the optimal way. Unfortunately...the client wants the person prompted for initials every time they save a record and proceed to enter a new record. He also doesn't want them to be able to go back and clear their initials from the textbox on the form once they enter them.
I guess I should try to retain the initials in the textbox,(once properly entered and they match the list), and dim out the textbox with the current initials until the user is done entering data for all the records the intend to enter. The initials stay with each record.
bph
|
|

March 4th, 2004, 12:25 PM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Do your users log in to a network? If so, you can use an API call to retrieve the network login. Store the network logins in a table with a field for the user initials. Then use a function in the before update event of any form that requires initials to set the initials. If you need the initials displayed, lock the textbox so users don't change each others entered/edited records.
To get the user login, I declare the API at the top of a standard module, below the option statements.
Private Declare Function GetUserNameA Lib "advapi32" (ByVal lpBuffer As String, _
lngSize As Long) As Long
Then write a function to call the api and return a string containing the name:
Public Function fnUserName() As String
Dim strRet As String * 256
If GetUserNameA(strRet, Len(strRet)) <> 0 Then
fnUserName = Left$(strRet, InStr(1, strRet, vbNullChar) - 1)
End If
End Function
Once you have the user name, you can use it in place of the initials or do a dLookup or open a recordset to retrieve the initials. If you write a function to return the user name, you can set the value of the locked bound text box to the return value of that function in the form before update event.
It's best not to depend on users to do things if you can automate the procedure yourself.
Ciao
Jürgen Welz
Edmonton AB Canada
[email protected]
|
|
 |