Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"OK" Button Not Working

Status
Not open for further replies.

jdwm2310

Technical User
Jul 26, 2001
396
US
Hi,

I have an "OK" button that should open up a form based on the user's username and password, I also included an option box that gives the option to either view the form in an "Add Mode" or "Preview Mode". So the process should look something like this: username - password - select option - click "OK" to open form.
But when I type an username and a wrong password I am still able to open the form...Can someone take a look at the code below to see if I did anything wrong..thanks!!!!


Private Sub OK_Click()
If IsNull(Me.cbousername) Then

Exit Sub

Else
Dim strpass As Variant
strpass = DLookup("Password", "User", "[UserName] = cboUserName")

Dim strFlag As Variant
strFlag = DLookup("Systemadmin", "User", "[UserName] = cboUserName")

If strpass = txtPassword Then
strGlobalUser = cbousername
strGlobalPass = strpass
strGlobalFlag = strFlag
DoCmd.Close
DoCmd.OpenForm "HelpDeskCalls", , , , acFormAdd
Forms!HelpDeskCalls![cboAssigned].Value = strGlobalUser

Else
MsgBox "Incorrect Username or Password entered.", vbOKOnly, "Logon Error"

If Frame19.Value = 1 Then
DoCmd.OpenForm "HelpDeksCalls", , , acPreview
Else
DoCmd.OpenForm "HelpDeskCalls", acNormal, [TicketNumber]


End If
End If
End If
End Sub
 
Looks like your nested IF is not properly nested. Reading the code above, even if the password doesn't match, you still open the form "HelpDeskCalls" as either acPreview or acNormal, depending on the value of Frame19.

Perhaps you need to move the "If Frame19..." above the previous "ELSE".

K.Hood
 
K.Hood,

I moved the If Frame19 and I still am able to open the form:

Private Sub OK_Click()
If IsNull(Me.cbousername) Then

Exit Sub

Else
Dim strpass As Variant
strpass = DLookup("Password", "User", "[UserName] = cboUserName")

Dim strFlag As Variant
strFlag = DLookup("Systemadmin", "User", "[UserName] = cboUserName")

If Frame19.Value = 1 Then
DoCmd.OpenForm "HelpDeskCalls", , , acPreview
Else
DoCmd.OpenForm "HelpDeskCalls", acNormal, [TicketNumber]

If strpass = txtPassword Then
strGlobalUser = cbousername
strGlobalPass = strpass
strGlobalFlag = strFlag
DoCmd.Close
DoCmd.OpenForm "HelpDeskCalls", , , , acFormAdd
Forms!HelpDeskCalls![cboAssigned].Value = strGlobalUser

Else
MsgBox "Incorrect Username or Password entered.", vbOKOnly, "Logon Error"

If Frame19.Value = 1 Then
DoCmd.OpenForm "HelpDeksCalls", , , acPreview
Else
DoCmd.OpenForm "HelpDeskCalls", acNormal, [TicketNumber]


End If
End If
End If
End If
End Sub
 
jdwm2310,

It looks like you copied it, not moved it. The way your logic works, if the password doesn't match it STILL will check Frame19.value & open the form. You may want to look at some documentation on how nested If statements work.

I don't know the full details of what you are trying to do, but here is how I think THIS PARTICULAR problem will be corrected:

Private Sub OK_Click()
If IsNull(Me.cbousername) Then

Exit Sub
End If

Dim strpass As Variant
strpass = DLookup("Password", "User", "[UserName] = cboUserName")

Dim strFlag As Variant
strFlag = DLookup("Systemadmin", "User", "[UserName] = cboUserName")


If strpass = txtPassword Then
strGlobalUser = cbousername
strGlobalPass = strpass
strGlobalFlag = strFlag
DoCmd.Close

If Frame19.Value = 1 Then
DoCmd.OpenForm "HelpDeskCalls", , , acPreview
Else
DoCmd.OpenForm "HelpDeskCalls", acNormal, [TicketNumber]

Forms!HelpDeskCalls![cboAssigned].Value = strGlobalUser
End If
Else
MsgBox "Incorrect Username or Password entered.", vbOKOnly, "Logon Error"

End If
End Sub


>>>> DoCmd.OpenForm "HelpDeskCalls", , , , acFormAdd

I removed the statement above, because I'm not sure that you need it. Keep in mind, I don't know everything about what you are doing - I'm trying to write this for you, just give you an idea of what it probably should look like.

K.Hood
 
Meant to say "I'm NOT trying to write this for you".
 
khood,

Don't worry about writing it, I got it..thanks for all your help, it was greatly appreciated....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top