I have been making a program I use this code
Option Explicit
Dim msg As String
Dim dlgdef As String
Dim Caption As String
Private Sub cmdOK_Click()
If txtusername.Text = Master Then
If txtpassword.Text = M4573r5hip Then
Load (frmAdmin.frm)
Else
msg = "Incorrect Password"
dlgdef = "vbOKOnly"
Caption = "Incorrect Password"
MsgBox(msg, dlgdef, caption)
End If
Else
msg = "Incorrect Username"
dlgdef = "VbOKOnly"
Caption = "Incorrect Username"
MsgBox(msg, dlgdef, caption)
End Sub
When I edit something on the lines opening the message boxes and click on something else or go to a different line I get the error
Compile Error:
Expected: =
Any idea why I get this error?
Your error is on the MsgBox lines.
Because you're using ( ) after msgbox you must have a return value.
Do either of these:
1: Remove the ( ) e.g.
MsgBox(msg, dlgdef, caption)
into
MsgBox msg, dlgdef, caption
2. Add a variable to return a value to.
dim dummy
dummy = MsgBox(msg, dlgdef, caption)
You also need the " " around M4573r5hip as already noted.
Oh and since this is on a form you can't use the name Caption for any of your variables since it's already a part of the form. (Window title)
edit:
As sk89q noted, vbOKOnly is a constant but not only do you need to remove the quotes but you should use the correct datatype for dlgdef which believe is integer, definitely not string. I might be a long but I doubt it.