Referencing a form name in a variable

  • Thread starter George Stevenson
  • Start date
G

George Stevenson

I've got a checkbox control of my general search form which specifies which
of 2 forms I want to display. I'm executing the following code to set the
name of the form I want to display.
If Me.chkSTrForm.Value = True Then
myForm = "frmSubTrustee"
Else
myForm = "frmGES"
End If

In a later event, I've got the following code which builds my SQL statement
and then opens the form. This was working fine when I had specified the
actual name of the form, but now that I've changed it to a variable, its
giving me an error message on the RecordSource statement.
mySQL = "SELECT * FROM GES " & _
"WHERE " & mySQLOpt1 & mySQLOpt2 & mySQLOpt3 & _
" [OwnerName] Like ""*" & varTrimmedName & "*"" ORDER BY
[estselldate]"
DoCmd.OpenForm myForm, acNormal, , , acFormEdit, acHide,
"suppressIE=True"
DoEvents
Forms!myForm.RecordSource = mySQL

I need a level of indirection to be able to use the variable name.

What is the proper syntax to use in the statement
Forms!myForm.RecordSource = mySQL
in order to have VBA recognize that the form name is loaded in the variable
name myForm?
 
S

Scott McDaniel

Try Forms(myForm).Recordsource = blah

Your code was trying to find an actual form named "myForm" and, of course,
there was none.
 

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