Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Sub Form Code

Geek News

Sub Form Code
Michael Conroy 11/10/2008 7:26:00 PM
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
--
Michael Conroy
Stamford, CT
Re: Sub Form Code
"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_gmail.com> 11/10/2008 7:42:07 PM
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
http://I.Am/DougSteele
(no e-mails, please!)


"Michael Conroy" <MichaelConroy[ at ]discussions.microsoft.com> wrote in message
news:0DC8B1C6-659B-44BB-95EC-7CA8E28E7165[ at ]microsoft.com...
[Quoted Text]
>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
> --
> Michael Conroy
> Stamford, CT


Re: Sub Form Code
Michael Conroy 11/10/2008 8:21:00 PM
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" wrote:

[Quoted Text]
> 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
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Michael Conroy" <MichaelConroy[ at ]discussions.microsoft.com> wrote in message
> news:0DC8B1C6-659B-44BB-95EC-7CA8E28E7165[ at ]microsoft.com...
> >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
> > --
> > Michael Conroy
> > Stamford, CT
>
>
>
Re: Sub Form Code
"tkelley via AccessMonster.com" <u47368[ at ]uwe> 11/10/2008 9:47:29 PM
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 Conroy wrote:
[Quoted Text]
>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]
>> >
>> > As always and help will be greatly appreciated. Thanks

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200811/1

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net