Results 1 to 3 of 3
  1. #1
    SPE_NY is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Posts
    4

    On Open form event not working

    Please could you tell me where I am going wrong

    I want to open 1 of 2 forms depending if a certain text is present in a field of a table.

    If text "Expired" is present in the 'Name' field of Table 'MAIN' then open form 'Expired' and if is not present open form 'Data_In'.

    The following code in the 'On Open' Event Criteria of a Hidden form, and does not work, that is to say neither form opens:

    Private Sub Form_Open(Cancel As Integer)
    If DCount("Name", "MAIN", "Expired") = 0 Then
    DoCmd.OpenForm "Data_In", acNormal


    Else
    DoCmd.OpenForm "Expired", acNormal
    End If
    End Sub

    Very new to this so suggested code to use in above sub routine would be appreciated.

    Thanks in advance

    Stephen

  2. #2
    pdebaets is offline Competent Performer
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Los Angeles
    Posts
    235
    Try this:

    Code:
    Private Sub Form_Open(Cancel As Integer)
    If DCount("*", "MAIN", "[Name] = 'Expired'") = 0 Then
        DoCmd.OpenForm "Data_In", acNormal
    Else
        DoCmd.OpenForm "Expired", acNormal
    End If
    End Sub

  3. #3
    SPE_NY is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Posts
    4
    Peter,
    Many thanks for your reply to my thread. Yes it is just what I wanted and works perfectly.
    I appreciate the time spent in replying.
    Thanks

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

Similar Threads

  1. Open Report Filter Stopped Working
    By ggs in forum Reports
    Replies: 5
    Last Post: 09-27-2011, 05:05 AM
  2. Replies: 21
    Last Post: 02-14-2011, 02:51 PM
  3. Open up url page hyperlink not working!
    By riffraff_ashraf in forum Forms
    Replies: 1
    Last Post: 09-29-2010, 09:33 AM
  4. combobox.dropdown event not working after error
    By perlyman in forum Programming
    Replies: 1
    Last Post: 04-02-2010, 06:55 PM
  5. Not In List event not working
    By Bruce in forum Forms
    Replies: 1
    Last Post: 03-12-2010, 02:24 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