Forms Coding

C

Chris

I am trying to open a form and assign a record source and
then filter the record source. I keep getting a "From"
error and a Can't find form error when I run the following
code.

Sub AA_Click()
Dim F As Form
Dim D As Database
Set F = Forms![frmEmp]
DoCmd.OpenForm "frmEmp", acNormal
F.RecordSource = "Select [Application_User_Name] from
tblEmployees" & "Where [Section_ID] = 'AA'"
F.Requery
End Sub

Any help is appreciated.

-Chris
 
M

Marshall Barton

Chris said:
I am trying to open a form and assign a record source and
then filter the record source. I keep getting a "From"
error and a Can't find form error when I run the following
code.

Sub AA_Click()
Dim F As Form
Dim D As Database
Set F = Forms![frmEmp]
DoCmd.OpenForm "frmEmp", acNormal
F.RecordSource = "Select [Application_User_Name] from
tblEmployees" & "Where [Section_ID] = 'AA'"
F.Requery
End Sub

You are trying to set a form object before the form is
opened. Try moving the Set F line after the OpenForm line.

Actually, in this case there is no need to assign a form
object variable. Once the form is opened, you can reference
it using the syntax Forms!formname. E.g.

Sub AA_Click()
DoCmd.OpenForm "frmEmp", acNormal
Forms!frmEmp.RecordSource = "Select . . ."
End Sub

Note that it's a waste of time to Requery the form since
setting it's RecorSource property automatically requerys
the data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top