If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Using VB in Access

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-25-10, 10:23
Jesnie Jesnie is offline
Registered User
 
Join Date: Jun 2010
Posts: 12
Using VB in Access

Hello, I've learned how to created a login form through a youtube tutorial for my database. It has instructed me to create a button that has the following event procedure (using code builder).

Username.SetFocus
If Username = "staff1" And Password = "staff1" Then
MsgBox "Access Granted", vbInformation, "CD Shop"
MsgBox "Welcome", vbInformation, "CD Shop"
DoCmd.Close
DoCmd.OpenForm "F_Switchboard_MainMenu"
ElseIf Username = "staff2" and Password = "staff2" Then
MsgBox "Access Granted", vbinformation, "CD Shop"
MsgBox "Welcome", vbinformation, "CD Shop"
DoCmd.Close
DoCmd.OPenForm "F_Switchboard_MainMenu"
ElseIf Username = "manager1" and Password = "manager1" Then
MsgBox "Welcome, Manager", vbinformation, "Manager Area"
MsgBox "Please Exercise Caution When Altering Back End", vbinformation, "Manager Area"
DoCmd.Close
DoCmd.OPenForm "F_Switchboard_MainMenu"
Else
MsgBox "Please re-enter your Username and Password."
End If

The button runs perfectly.

However, when i tried to save it, a message box appears.
Run-time error '3709':
The search key was not found in any record.

The next time I opened the database and tried to log in, the button no longer works anymore.

If you dont mind, can you kindly please explain to me why does this happen and what can i do to solve this error?

I'm just a beginner in using Ms Access and Visual Basic, so much explanation is needed.

Please help me. Thank you.
Reply With Quote
  #2 (permalink)  
Old 06-25-10, 11:05
NTC NTC is offline
Registered User
 
Join Date: Oct 2009
Posts: 340
ummm...well; you disable code by putting a: ' at the beginning of the line

so you should cut this down into single elements and test.

Username.SetFocus really should be me.Username.SetFocus and is a distraction at the moment so I would disable it.

I prefer the Case method rather than ElseIf - but as a newbie I would even further suggest you chop those up into separate If/And - - it is much easier for you to understand.

If Username = "staff1" And Password = "staff1" Then
MsgBox "Access Granted", vbInformation, "CD Shop"
MsgBox "Welcome", vbInformation, "CD Shop"
DoCmd.Close
DoCmd.OpenForm "F_Switchboard_MainMenu"

If Username = "staff2" and Password = "staff2" Then
MsgBox "Access Granted", vbinformation, "CD Shop"
MsgBox "Welcome", vbinformation, "CD Shop"
DoCmd.Close
DoCmd.OPenForm "F_Switchboard_MainMenu"

If Username = "manager1" and Password = "manager1" Then
MsgBox "Welcome, Manager", vbinformation, "Manager Area"
MsgBox "Please Exercise Caution When Altering Back End", vbinformation, "Manager Area"
DoCmd.Close
DoCmd.OPenForm "F_Switchboard_MainMenu"
Else
MsgBox "Please re-enter your Username and Password."
End If

this way you can disable each section cleanly - and test bit by bit......
Reply With Quote
  #3 (permalink)  
Old 06-25-10, 11:06
NTC NTC is offline
Registered User
 
Join Date: Oct 2009
Posts: 340
sorry forgot - each of those sections needs to have
EndIf
Reply With Quote
  #4 (permalink)  
Old 06-25-10, 11:25
Jesnie Jesnie is offline
Registered User
 
Join Date: Jun 2010
Posts: 12
hey thank you. I've changed it. but then, now instead of run-time error '3709', it became

Run-time error '2467'
The expression you entered refers to an object that is closed or doesn't exist.

And if I click the debug button,
the Visual Basic highlights the first line of the second section. Oh and if I hover over that line, a bubble pops up saying ' Password = < The expression you entered refers to an object that is closed or...'

do you know what am i supposed to do?

Last edited by Jesnie; 06-25-10 at 11:33.
Reply With Quote
  #5 (permalink)  
Old 06-28-10, 18:09
NTC NTC is offline
Registered User
 
Join Date: Oct 2009
Posts: 340
oh - you are closing the form you are working in.....

take out all those docmd.close

in the open of the new form it will open on top of the existing form....generally that is ok and actually preferable... but if not then put in one docmd.close at the bottom of the code after whichever form is going to open has opened....

before that close command - you have to reset the focus to the current form.....so it won't think you are trying to close the form that was just opened...so reset the focus on your current form...
me.focus
docmd.close....
Reply With Quote
  #6 (permalink)  
Old 06-28-10, 18:36
Poppa Smurf Poppa Smurf is offline
Registered User
 
Join Date: Jun 2007
Location: Sydney,Australia
Posts: 346
Why have you started another thread when you also have the same problem listed at http://www.dbforums.com/microsoft-access/1657915-login-form-vbulletin.html.

Various memebrs has spent time replying to your previous thread, please read your previous thread for some advice.
__________________
Poppa Smurf
allanmurphy47@gmail.com
Reply With Quote
  #7 (permalink)  
Old 06-29-10, 01:04
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
Quote:
Originally Posted by Poppa Smurf View Post
Why have you started another thread when you also have the same problem listed at http://www.dbforums.com/microsoft-access/1657915-login-form-vbulletin.html.

Various memebrs has spent time replying to your previous thread, please read your previous thread for some advice.
...good point, and well made
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Tags
login form, ms access, run-time '3709', visual basic

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 On
Pingbacks are On
Refbacks are On