954,566 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

stephen_UK
Light Poster
36 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

The syntax you're using for your DCOUNT function is incorrect. If you use something like this:

DCount("Name", "MAIN", "Name = 'Expired'")

...then it should give you the count you're looking for. However, since you are actually looking for a simple count of rows that fit the criterion, you could (for simplicity's sake, and to avoid future confusion) use this:

DCount("*", "MAIN", "Name = 'Expired'")

Hope this helps. Good luck!

BitBlt
Master Poster
711 posts since Feb 2011
Reputation Points: 367
Solved Threads: 109
 

Many thanks
That is what was required
Cheers

Stephen

stephen_UK
Light Poster
36 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: