Open Form filtered

  • Thread starter Thread starter alex
  • Start date Start date
A

alex

Open Form filtered

Using Access ’03…

I am attempting to open a form (from another) filtered.

I have this code:

Dim strDocName As String
strDocName = "frm1”
Dim strCriteria As String
strCriteria = "[Key] = " & Q & Replace(Me.Key, Q, QQ) & Q

DoCmd.OpenForm strDocName, , , strCriteria
DoCmd.Close acForm, me.name

Debug.Print (strCriteria)

I cannot get frm1 to open with the filtered record…it (the form)
displays all records.
The code in the immediate window looks right: [Key] = “5042”

Do I need to adjust the properties of frm1? It’s a form for viewing
only, no data entry or edits.

Thanks,
alex
 
Make a copy of the query that is the record source of the query for frm1.
Now in design view of query, put in the criteria 5042 for the key field.
Switch to datasheet view and see if there are any records.

Check that [Key] is a number field and not a text field.
If it is a text field, you will need to do the qutoes differently.
Here is an example-->

"[Key] = """ & Me.[TextField] & """"



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia

Open Form filtered

Using Access ’03…

I am attempting to open a form (from another) filtered.

I have this code:

Dim strDocName As String
strDocName = "frm1”
Dim strCriteria As String
strCriteria = "[Key] = " & Q & Replace(Me.Key, Q, QQ) & Q

DoCmd.OpenForm strDocName, , , strCriteria
DoCmd.Close acForm, me.name

Debug.Print (strCriteria)

I cannot get frm1 to open with the filtered record…it (the form)
displays all records.
The code in the immediate window looks right: [Key] = “5042”

Do I need to adjust the properties of frm1? It’s a form for viewing
only, no data entry or edits.

Thanks,
alex
 
Make a copy of the query that is the record source of the query for frm1.
Now in design view of query, put in the criteria 5042 for the key field.
Switch to datasheet view and see if there are any records.

Check that [Key] is a number field and not a text field.
If it is a text field, you will need to do the qutoes differently.
Here is an example-->

"[Key] = """ & Me.[TextField] & """"

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Open Form filtered

Using Access ’03…

I am attempting to open a form (from another) filtered.

I have this code:

Dim strDocName As String
strDocName = "frm1”
Dim strCriteria As String
strCriteria = "[Key] = " & Q & Replace(Me.Key, Q, QQ) & Q

DoCmd.OpenForm strDocName, , , strCriteria
DoCmd.Close acForm, me.name

Debug.Print (strCriteria)

I cannot get frm1 to open with the filtered record…it (the form)
displays all records.
The code in the immediate window looks right: [Key] = “5042”

Do I need to adjust the properties of frm1?  It’s a form for viewing
only, no data entry or edits.

Thanks,
alex

Thanks Jeanette, I'll give it a try.
alex
 
Back
Top