Forms Coding

  • Thread starter Thread starter Chris
  • Start date Start date
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
 
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.
 
Back
Top