Sub Form Code

M

Michael Conroy

I need to clearify whether or not my form naming convention is preventing my
code from running. The main form is named "frm MainMenu" and the subform is
"frm Options", and yes there is a space after the m, it makes it easier for
me to read it.

Now on my main form in the afterupdate event of the "WorkOptions" option box
I am grabbing the value and trying to change the recordsource of the sub
form. The code errors out saying it can't find the FIELD "frm Options", when
I expect it to be looking for a form. (Error 2465) I thought the square
brackets made it look like a field, but what else can you wrap around a form
name to cover spaces? The A97 code looks like this:

Dim Criteria As String
Dim strSQL As String
Dim Target As Byte
Target = Me.WorkOption
Criteria = "Category = " & Target
strSQL = "SELECT [tbl Options].* " & _
"FROM [tbl Options] " & _
"WHERE (" & Criteria & ");"
Me![frm Options]!Form.RecordSource = strSQL

As always and help will be greatly appreciated. Thanks
 
D

Douglas J. Steele

Depending on how you added frm Options as a subform, the name of the subform
control on frm MainMenu may be named something different than frm Options.
Double-check to ensure that you're using the name of the subform control.

Once you're sure that you are using the correct name, it needs to be .Form,
not !Form. Form is a property of the subform control, and you always refer
to properties using periods, not exclamation points.

And at the risk of annoying you, I don't agree that frm MainMenu and frm
Options are any easier to read than frmMainMenu and frmOption.
 
M

Michael Conroy

Douglas,
You found both my errors, thank you. The source of the subform is "frm
Options", but the name is just "Options". I changed the code to reference the
name and the exclaimation point to a dot and it worked.

And don't worry about bothering me about the nameing convention. I got into
that bad habit a few years ago before I knew there was a proper way to do
things. But you are right, it is probably time for me to use the proper
format. And since I am starting a new database, I will rename the few things
I have so far. Thanks again.
--
Michael Conroy
Stamford, CT


Douglas J. Steele said:
Depending on how you added frm Options as a subform, the name of the subform
control on frm MainMenu may be named something different than frm Options.
Double-check to ensure that you're using the name of the subform control.

Once you're sure that you are using the correct name, it needs to be .Form,
not !Form. Form is a property of the subform control, and you always refer
to properties using periods, not exclamation points.

And at the risk of annoying you, I don't agree that frm MainMenu and frm
Options are any easier to read than frmMainMenu and frmOption.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Michael Conroy said:
I need to clearify whether or not my form naming convention is preventing
my
code from running. The main form is named "frm MainMenu" and the subform
is
"frm Options", and yes there is a space after the m, it makes it easier
for
me to read it.

Now on my main form in the afterupdate event of the "WorkOptions" option
box
I am grabbing the value and trying to change the recordsource of the sub
form. The code errors out saying it can't find the FIELD "frm Options",
when
I expect it to be looking for a form. (Error 2465) I thought the square
brackets made it look like a field, but what else can you wrap around a
form
name to cover spaces? The A97 code looks like this:

Dim Criteria As String
Dim strSQL As String
Dim Target As Byte
Target = Me.WorkOption
Criteria = "Category = " & Target
strSQL = "SELECT [tbl Options].* " & _
"FROM [tbl Options] " & _
"WHERE (" & Criteria & ");"
Me![frm Options]!Form.RecordSource = strSQL

As always and help will be greatly appreciated. Thanks
 
T

tkelley via AccessMonster.com

A little more info to supplement Douglas' solution:

http://www.mvps.org/access/forms/frm0031.htm

Also, if you're married to the idea of having your "frm" be a character away
from your form name, you could try using the underscore instead of a space.
Just be consistent.

Michael said:
Douglas,
You found both my errors, thank you. The source of the subform is "frm
Options", but the name is just "Options". I changed the code to reference the
name and the exclaimation point to a dot and it worked.

And don't worry about bothering me about the nameing convention. I got into
that bad habit a few years ago before I knew there was a proper way to do
things. But you are right, it is probably time for me to use the proper
format. And since I am starting a new database, I will rename the few things
I have so far. Thanks again.
Depending on how you added frm Options as a subform, the name of the subform
control on frm MainMenu may be named something different than frm Options.
[quoted text clipped - 36 lines]
 

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