Results 1 to 5 of 5
  1. #1
    jlgray0127 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Location
    Central Illinois
    Posts
    185

    Opening Forms Via Criteria

    Hi!
    I have a form that populates with the user who is logged in.
    If the user is not on the user table, I want them to have to log their information into the User Table, in order to be in the form.

    I run a query against the person logged into the PC against the table that contains the Database user's information. If the user is in the user table, I want the main menu form to open. If the user is NOT in the table, I want the data base to open the registration form.

    The code below, is what I'm trying to use, but I'm a getting the error, Block If without End IF

    I'm not sure where I'm going wrong. Please help with my coding.

    Private Sub Form_Open(Cancel As Integer)
    If [CWS] Is Null Then
    MsgBox "New Users Must Register before proceeding! CWS, First and Last Name are Required to proceed.", vbOKOnly
    docmnd.OpenForm "AdminRegisterUsersForm"
    docmnd.closeform "AdminVerifyUsersForm"
    Else
    If [CWS] Is Not Null Then
    docmnd.OpenForm "Main_Menu"




    End If


    End Sub

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You have two IF statements, and only one END IF.
    You actually do not need the second IF at all. A value can only be Null or Not Null (there is no third option). So if does not meet the first check, you don't need to check the second thing, i.e.
    Code:
    Private Sub Form_Open(Cancel As Integer)
    
    If [CWS] Is Null Then
        MsgBox "New Users Must Register before proceeding! CWS, First and Last Name are Required to proceed.", vbOKOnly
        DoCmd.OpenForm "AdminRegisterUsersForm"
        DoCmd.Close acForm, "AdminVerifyUsersForm"
    Else
        DoCmd.OpenForm "Main_Menu"
    End If
    
    End Sub
    Also, it is "DoCmd", not "Docmnd" (no "n") and "CloseForm" is not a valid command.

  3. #3
    jlgray0127 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Location
    Central Illinois
    Posts
    185
    Thank you, Joe.
    This did not work, however. Running the code just as above, I get a compile Error: Method or data member not found.
    The form this is applied to, is the AdminVerifyUsersForm, so wondering if it's because I'm trying to close the same form I'm running the code in, with the If method. Not really sure. Checked all my spelling this time, as well! Thanks for catching the Cmnd... lol... rookie mistake!
    I tried taking out the close form line, to test this and received the error Object Required

    I APPRECIATE YOUR HELP!!!!!!

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Here are some tricks to use to help debug some of your syntax.

    First, try creating a Macro to do some of these commands (like opening and closing forms).
    Once you get the Macro working properly, you can highlight it, go to the Database Tools menu and click on the "Convert Macros to Visual Basic" button. This will give you the exact VBA syntax you need to perform those actions.

    Also, in debugging current VBA code, I would recommend commenting out certain lines, to see which ones work and which don't, to nail down exactly which line is causing your issues.

    So, I recommend trying the first thing with your Open/Close form commands, and see if that gets it working properly.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    "[CWS] Is Null" is the SQL syntax (I think).

    You might want to try the VBA IsNull() function.
    Code:
    If IsNull([CWS]) Then

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Opening Forms Maximized
    By data808 in forum Forms
    Replies: 3
    Last Post: 04-29-2014, 04:37 PM
  2. Replies: 3
    Last Post: 10-23-2013, 08:11 AM
  3. Opening multiply Forms?
    By djclntn in forum Forms
    Replies: 10
    Last Post: 04-02-2013, 04:20 PM
  4. Opening a report with search criteria through a combo box
    By very_much_a_beginner in forum Reports
    Replies: 1
    Last Post: 07-16-2012, 01:30 PM
  5. Two forms opening the same form
    By MikeMairangi in forum Forms
    Replies: 5
    Last Post: 08-31-2011, 01:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums