openform with criteria

groengoen

Registered User.
Local time
Today, 22:05
Joined
Oct 22, 2005
Messages
141
I open a form with a criteria set but when the form opens it has every record, rather than restricting the records to those matching the criteria. I wonder if anyone has had this problem before? I use a query in the called to get the underlying recordset.

This is my code:

Dim CritText As String

CritText = "[ID1] = '" & Me.ID1 & "'"
DoCmd.OpenForm "frmTestAll", acFormDS, , stCritText
 
Do you have:
Option Compare Database
Option Explicit

at the top of your code module of the form?
 
I might be wrong but try this instead:

Dim CritText As String

CritText = "[ID1] = " & Me.ID1
DoCmd.OpenForm "frmTestAll", acFormDS, , stCritText
 
If you follow my suggestion the compiler will find the typo for you!
 
I did have Option Compare Database, but not Option Explicit. It eventually decided to work after I tried to put in OpenArg variable as a last resort. I never used the OpenArg, the where condition just seemed to work when I added the extra parameter. Here is my current code: I added an extra OR once it was working. Maybe someone would know why it works now!

Dim CritText As String
Dim stId1 As String

Name1.SetFocus
CritText = "[ID1] = '" & Me.ID1 & "' OR [ID2] = '" & Me.ID1 & "' "
stId1 = Me.ID1
DoCmd.OpenForm "PolicyForIDSubf", acFormDS, , CritText, , , stId1

Thanks for the help
 
PS. I know the form is different, but I was just using a test form until I got it right
 

Users who are viewing this thread

Back
Top Bottom