 |
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
|
|
|

February 18th, 2004, 05:34 PM
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Where do i put the code?
I have some code I would like to see run after a form has opened and is viewable by the user.
It's an input box which asks a user to enter his or her initials. On open I set focus to the textbox that I would like the entry made. Then I would like the input box to come up allowing the entry.
I tried the lost focus event, but if the user goes back to the textbox, it comes at them again and that isn't good.
Here's the code I'm using. Anyway around the user taking cancel and totally avoiding this entry? It can't be null, and the user can't do a cancel. Aside from required set on textbox which I curently use.
*****************************************
Dim strInput As String, strMsg As String
strMsg = "Please enter your Initials."
strInput = InputBox(Prompt:=strMsg, _
Title:="Action Required", XPos:=5000, YPos:=5000)
MsgBox "Thank You, " & strInput
********Thanks, BPH
|

February 18th, 2004, 05:54 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Put this on the form's ON OPEN event, assuming that the textbox that holds the initials is called Me.txtInitials:
Code:
Dim strInitials as String
strInitials = ""
Do While strInitials = ""
strInitials = Trim(InputBox("Please enter your initials.","User Initials"))
Loop
Me.txtInitials = strInitials
Me.txtInitials.SetFocus
The do loop is there to prevent someone from entering nothing as initials. It will keep asking until the person enters something. If you don't specify a box location, the input box will default to dead center of the screen.
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|

February 18th, 2004, 11:06 PM
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Thanks Greg. I'll give it a shot.
[size=1]
Quote:
quote:Originally posted by SerranoG
Put this on the form's ON OPEN event, assuming that the textbox that holds the initials is called Me.txtInitials:
Code:
Dim strInitials as String
strInitials = ""
Do While strInitials = ""
strInitials = Trim(InputBox("Please enter your initials.","User Initials"))
Loop
Me.txtInitials = strInitials
Me.txtInitials.SetFocus
The do loop is there to prevent someone from entering nothing as initials. It will keep asking until the person enters something. If you don't specify a box location, the input box will default to dead center of the screen.
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

February 19th, 2004, 09:31 AM
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
This works well. But..There's always a what if....the user decides she/he doesn't want to go into the form after all. How can allow for a graceful exit from the input box?
|

February 19th, 2004, 09:43 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Quote:
quote:Originally posted by bph
This works well. But..There's always a what if....the user decides she/he doesn't want to go into the form after all. How can allow for a graceful exit from the input box?
|
In that case, skip the DO LOOP altogether and just accept any initials. Check for no input.
Code:
Dim varInitials as Variant
varInitials = InputBox("Please enter your initials.","User Initials")
If IsNull(varInitials) Then
'No initials entered. Assume they don't want to put any.
'Enter some code here to do something else, e.g. close the form.
Else
Me.txtInitials = Trim(varInitials)
Me.txtInitials.SetFocus
End If
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|

February 19th, 2004, 12:12 PM
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Excellent...
Here's what I ended up with. I incorporated your thoughts into the final product. If the user doesn't enter initials they go nowhere. If they enter initials that don't match the initials in a table that sits behind the initial field on the form, then I let the form open and they can't proceed until they select their initials from a drop down box.
Now....FYI- this is a data entry form. I want this same input box routine to run after a user has saved their entries, and moved to input data in the next record. So They save, next blank form appears and boom, the have to enter their initials.
I tried the "after insert" event, and the "after update" event. The input box pops up too early, before the next blank record is viewed. Want to see the next blank record, then prompt for initials.
Make sense? Where do I stick this code to make that happen?
****************************
Private Sub Form_Open(Cancel As Integer)
On Error GoTo NoInitialsEntered
Dim varInitials As Variant
varInitials = InputBox("Please enter your initials.", "User Initials")
If 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
End Sub
|

February 19th, 2004, 12:19 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Move the entire code from the ON OPEN event to the ON CURRENT event. This will activate it everytime you move from record to record. However, if you DON'T want it happen for previously entered records and you ONLY want it to happen to NEW records, you need to surround the whole thing with
Code:
If Me.NewRecord
...
End If
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|

February 19th, 2004, 02:50 PM
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Got it.! Thanks, BPH
|
|
 |