problem with my code

J

Joel Wiseheart

I don't see a single bang...

When separating parent objects from child objects (For
instance, the parent form and the child combo box on the
form), you should separate it with a "!" character,
sometimes called a "bang". Using the "." character
separates objects from their properties and methods. Try
statements like the following:
If IsNull(Me!cbousername) Or Me!cbousername = "" Then
MsgBox "You must enter a User Name." _
, vbOKOnly, "Required Data"
Me!cbousername.SetFocus
Exit Sub
End If

Notice that on the third line, the "!" separates the Me
reference to the parent form from the child object
cbousername, but a "." separates the cbousername object
from its SetFocus method.

Also, I don't know if your newsgroup post looks identical
to your code, but in case it does, you'll also notice
that I included a "line continuation" character, which is
a space followed by an underscore " _" after the first
comma in the MsgBox staement. Any time you want to
continue a command to the next line in the middle of a
statement, you need to include that character.

Also, I'm assuming this code is in a Form Module. If you
use a Standard module, you surrender the right to use
the "Me" reference, and have to use the fully qualified
form reference.

One final note, without getting into a lengthy discussion
here, check out the help files on using a With....End
With contsruct. You'll notice it will trim quite a bit
out of the code you listed.

hth
Joel
-----Original Message-----
listed below is the code i have written that is not working any help would
be great if you can show me where i went wrong as i am new to this side.
thanks in advance.

Private Sub cmdlogin_Click()

'Check to see if data is entered into the UserName combo box

If IsNull(Me.cbousername) Or Me.cbousername = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cbousername.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.txtpassword) Or Me.txtpassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtpassword.SetFocus
Exit Sub
End If

'Check value of password in usyspassword to see if this
'matches value chosen in combo box

If Me.txtpassword.Value = DLookup
("Password", "usyspassword", "[ID]=" &
Me.cbousername.Value) Then

ID = Me.cbousername.Value

'Close logon form and open splash screen
If Me.cbousername.Value = "admin" Then
DoCmd.Close
DoCmd.OpenForm "pers", acNormal, , "[group] = 1"
ElseIf passwd = "b" Then
DoCmd.Close
DoCmd.OpenForm "pers", acNormal, , "[group] = 2"
ElseIf passwd = "c" Then
DoCmd.Close
DoCmd.OpenForm "pers", acNormal, , "[group] = 3"
Else
DoCmd.Close
DoCmd.OpenForm "pers", acNormal, , "[group] = 4"
End If

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtpassword.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database.Please contact admin.",
vbCritical, "Restricted Access!"
Application.Quit
End If





Exit_cmdlogin_Click:
Exit Sub

End Sub






.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top