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

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!

Many thanks
That is what was required
Cheers

Stephen