VBA Help in MS Access 2003

spike250

Registered User.
Local time
Today, 19:38
Joined
Aug 6, 2009
Messages
70
Hi All,

I am trying to get a logon page that opens different forms depending on the selection in the combo box.

I have obtained code for the logon form from www.databasedev.co.uk/login.html

This works fine when I have only one form to open, but as my combox has 19 different entries which inlude user names and a seperate txt field for a password. I am unsure how to link each entry to its own form when the user selects login?

Any help would be much appreciated.

Regards

Spike
:cool:
 
It sounds like you need an extra field in your combo - assuming your logon data is stored in a table then you'll need to add a text field to that table and then add it into the combo. Don't forget to add one to the Column Count and to add an extra Column Width of zero.

The extra field will store the name of the form you want to open for that particular person. In the AfterUpdate of the combo you need this code:

DoCmd.OpenForm Me!ComboName.Column(2)

This is for if the new field is the 3rd column in your combo (3rd field in the rowsource), as column indexes start counting from zero.
 
Hi Kafrin,

I have tried what you have suggested and I get the following error;

Run-Time error 2494
The action or method required a form Name Argument.

Any suggestions.

What you have suggested is great and is what I am after if i can get it to work but I need to to run when the user selects login,

I have a field in my table called password and some code in the form that checks the entry so I would need it to run for each person after they have typed in there password and clicked logon (security reasons)

Regards

Spike
:cool:
 
OK, so clearly for your case the code goes on the OnClick of the Logon button (rather than the After Update that I previously stated), and after you check the password.

I'm guessing that the problem comes if you haven't entered a form name against a person, so possibly you need a check for a valid form.

Your existing code presumably checks to see if the password is correct. So you want:

If PasswordCorrect Then

If Not IsNull(Me!ComboName.Column(2)) Then
DoCmd.OpenForm Me!ComboName.Column(2)
Else
...what to do if there's no specified form (open a default form?)...
End If

End If


Don't forget as well that you want the name of the form, not the caption on the form. And make sure you use the correct column number to match up with your combo (remember it starts counting at 0).
 
Hi Kafrin,

Thanks for the response, the code works perfectly.

Thanks for your help.

Spike
 

Users who are viewing this thread

Back
Top Bottom