Error when opening a form

law

Registered User.
Local time
Today, 12:45
Joined
Feb 14, 2004
Messages
26
Can anyone help with this small problem I am having when I open this form. I get an error message which says "The action or method requires a form name or argument" I have declared the form name but it is still not happy!

Private Sub commandStaffAddDetails_Click()
Dim username As String
Dim pwd As String

username = InputBox("Please enter your username ")
If username = "whatever" Then

pwd = InputBox("Please enter your password")
If pwd = "whatever" Then

DoCmd.OpenForm formStaffDetails, , True
Else
MsgBox "Username & password needed to view staff details form", vbCritical, "Restricted Area"
End If
End If
End Sub

any ideas?

Thanks
 
I believe you need quotes around the form name. Try this:


DoCmd.OpenForm "formStaffDetails", , True
 
Error with form

Thanks very much that worked!
 
You have a flaw in your if statement. What happens if they do not type the
correct user name? Try this...
Code:
Private Sub commandStaffAddDetails_Click()
    
    Dim sUserName As String
    Dim sPassword As String
    
    sUserName = InputBox("Please enter your username", "User Name")
    If sUserName = "whatever" Then
        sPassword = InputBox("Please enter your password", "Password")
        If sPassword = "whatever" Then
            DoCmd.OpenForm "formStaffDetails", , True
        Else
            MsgBox "Password needed to view staff details form.", vbCritical, "Restricted Area"
            Exit Sub
        End If
    Else
        MsgBox "User name needed to view staff details form.", vbCritical, "Restricted Area"
        Exit Sub
    End If
    
End Sub
I also suggest that you search for Mile-O-phile's posted login form.
I believe he has recently posted it this week.

HTH
 
Last edited:
ghudson said:
I also suggest that you search for Mile-O-phile's posted login form.

It's on this thread.

Read the post though as there's one slight error; namely something I forgot to remove before I uploaded the sample.
 

Users who are viewing this thread

Back
Top Bottom