Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 18th, 2004, 05:34 PM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Location: , , .
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #2 (permalink)  
Old February 18th, 2004, 05:54 PM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
Reply With Quote
  #3 (permalink)  
Old February 18th, 2004, 11:06 PM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Location: , , .
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #4 (permalink)  
Old February 19th, 2004, 09:31 AM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Location: , , .
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default

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?

Reply With Quote
  #5 (permalink)  
Old February 19th, 2004, 09:43 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
Reply With Quote
  #6 (permalink)  
Old February 19th, 2004, 12:12 PM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Location: , , .
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #7 (permalink)  
Old February 19th, 2004, 12:19 PM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
Reply With Quote
  #8 (permalink)  
Old February 19th, 2004, 02:50 PM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Location: , , .
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Got it.! Thanks, BPH
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
out put cyber_kaley20 Beginning PHP 2 October 5th, 2008 07:46 PM
Php code to put&get images from mysql not working! angelbeans PHP Databases 1 September 8th, 2006 12:44 PM
DISPLAY THE OUT PUT jhan316 PHP How-To 3 June 27th, 2006 05:05 AM
App wide code - where to put it? VictorVictor ASP.NET 2.0 Basics 5 May 31st, 2006 02:20 PM
How do I put this into a table? stacy Classic ASP Databases 3 February 3rd, 2004 07:52 AM



All times are GMT -4. The time now is 01:53 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.