Macros and SubForms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to write a macro that selects a certain record in Form A depending
on the contents of fields in a subform. We'll say the subform is in Form B.
If I open the subform as its own seperate form and run the macro, it
functions properly. If I attempt to run the macro from the subform (set to
OnClick on a button), it acts like it can't find the contents of the field.
Any suggestions?
 
the problem probably has to do with control references. what are the macro
Condition(s), Action(s), and ActionArguments for each action?
 
Macro is very simple, just an OpenForm with no conditional statements. It is
set to the OnClick event for a button. The only argument is the Where
Condition, which is as follows:

[strCardNum]=[Forms]![frmNameSelect]![strCardNum] And
[strShootDate]=[Forms]![frmNameSelect]![strDate] And
[strShootTime]=[Forms]![frmNameSelect]![strTime]

where [frmNameSelect] is my subform, which is in a form named frmPersonalInfo.

If frmNameSelect is opened on its own, the macro works like a charm. If the
button is clicked in the subform (when frmPersonalInfo is opened), it acts as
if it can't find the fields in frmNameSelect, pulling up a dialog box for me
to enter the information.
 
well, on reading your original post again, it sounds like you have FormA
open. you also have FormB open, and FormB has a subform in it. you want to
refer to controls within the subform that's on FormB - to filter records on
FormA.

assuming that the command button is on the subform itself (not on FormB),
try the following syntax, as

[strCardNum]=[strCardNum] And [strShootDate]=[strDate] And
[strShootTime]=[strTime]

if the command button is on FormB (not on the subform itself), then try

[strCardNum]=[frmNameSelect].Form![strCardNum] And
[strShootDate]=[frmNameSelect].Form![strDate] And
[strShootTime]=[frmNameSelect].Form![strTime]

the above syntax also assumes that the name of the *subform CONTROL* in
FormB is [frmNameSelect]. you need to double check, because sometimes the
name of a subform object in the database window is NOT the same as the name
of the subform control in the main form.

to check the subform control name in FormB: open the form in design view,
and click on the subform (within FormB's design view) ONCE to select it. in
the Properties box, click on the Other tab and look at the Name property.

hth


Mark said:
Macro is very simple, just an OpenForm with no conditional statements. It is
set to the OnClick event for a button. The only argument is the Where
Condition, which is as follows:

[strCardNum]=[Forms]![frmNameSelect]![strCardNum] And
[strShootDate]=[Forms]![frmNameSelect]![strDate] And
[strShootTime]=[Forms]![frmNameSelect]![strTime]

where [frmNameSelect] is my subform, which is in a form named frmPersonalInfo.

If frmNameSelect is opened on its own, the macro works like a charm. If the
button is clicked in the subform (when frmPersonalInfo is opened), it acts as
if it can't find the fields in frmNameSelect, pulling up a dialog box for me
to enter the information.

tina said:
the problem probably has to do with control references. what are the macro
Condition(s), Action(s), and ActionArguments for each action?


Form
B. (set
to
 
Still not working. :/ Let me list all the parts of the problem.

3 forms:
frmPersonalInfo (the main form)
main information pulled from here is the ID Card Number (strCardNum)
frmNameSelect (the sub-form, in frmPersonalInfo)
pulls information from a name-to-date table, listing ID card numbers,
dates, and times (strCardNum, strDate, strTime)
frmShootInfo (the form I wish to open with the OpenForm macro)
contains the ID card number, dates, and times used to populate the
name-to-date table

The macro only has the one action, the OpenForm, with the where condition as
you said to enter it above. It still acts as if it cannot find the
information to use to filter the results.

Does this help a little more? Thanks for the help already, btw!
tina said:
well, on reading your original post again, it sounds like you have FormA
open. you also have FormB open, and FormB has a subform in it. you want to
refer to controls within the subform that's on FormB - to filter records on
FormA.

assuming that the command button is on the subform itself (not on FormB),
try the following syntax, as

[strCardNum]=[strCardNum] And [strShootDate]=[strDate] And
[strShootTime]=[strTime]

if the command button is on FormB (not on the subform itself), then try

[strCardNum]=[frmNameSelect].Form![strCardNum] And
[strShootDate]=[frmNameSelect].Form![strDate] And
[strShootTime]=[frmNameSelect].Form![strTime]

the above syntax also assumes that the name of the *subform CONTROL* in
FormB is [frmNameSelect]. you need to double check, because sometimes the
name of a subform object in the database window is NOT the same as the name
of the subform control in the main form.

to check the subform control name in FormB: open the form in design view,
and click on the subform (within FormB's design view) ONCE to select it. in
the Properties box, click on the Other tab and look at the Name property.

hth


Mark said:
Macro is very simple, just an OpenForm with no conditional statements. It is
set to the OnClick event for a button. The only argument is the Where
Condition, which is as follows:

[strCardNum]=[Forms]![frmNameSelect]![strCardNum] And
[strShootDate]=[Forms]![frmNameSelect]![strDate] And
[strShootTime]=[Forms]![frmNameSelect]![strTime]

where [frmNameSelect] is my subform, which is in a form named frmPersonalInfo.

If frmNameSelect is opened on its own, the macro works like a charm. If the
button is clicked in the subform (when frmPersonalInfo is opened), it acts as
if it can't find the fields in frmNameSelect, pulling up a dialog box for me
to enter the information.

tina said:
the problem probably has to do with control references. what are the macro
Condition(s), Action(s), and ActionArguments for each action?


I'm trying to write a macro that selects a certain record in Form A
depending
on the contents of fields in a subform. We'll say the subform is in Form
B.
If I open the subform as its own seperate form and run the macro, it
functions properly. If I attempt to run the macro from the subform (set
to
OnClick on a button), it acts like it can't find the contents of the
field.
Any suggestions?
 
based on everything you've told me,

[strCardNum]=[strCardNum] And [strShootDate]=[strDate] And
[strShootTime]=[strTime]

should work. that's assuming that the names on the *left* side of each "="
pair are the correct names of the fields in in the RecordSource of
frmShootInfo; and the names on the *right* side of each "=" pair are the
correct names of the controls in the subform.

but it seems like people have more trouble getting control references to
work in macros, especially when subforms are involved. at this point, i'd
just throw up my hands and do it in VBA. again, if the command button is on
the subform (the location where a code, or macro, is called from makes a big
difference), add the following code to the button's Click event procedure,
as

DoCmd.OpenForm "frmShootInfo ", , , "strCardNum = '" _
& Me!strCardNum & "' And strShootDate = '" _
& Me!strDate & "' And strShootTime = '" & strTime & "'"

since all the fields are prefixed with "str", the above handles them all as
Text data types. if a field is a Number data type, the correct syntax would
leave off the single quotes, as

"strCardNum = " & Me!strCardNum

if a field is a Date/Time data type, the correct syntax would replace the
single quotes with the # sign, as

strShootDate = #" & Me!strDate & "#

if you don't know how to create an event procedure to house the code, post
back and i'll walk you through it, it's not hard.

hth


Mark said:
Still not working. :/ Let me list all the parts of the problem.

3 forms:
frmPersonalInfo (the main form)
main information pulled from here is the ID Card Number (strCardNum)
frmNameSelect (the sub-form, in frmPersonalInfo)
pulls information from a name-to-date table, listing ID card numbers,
dates, and times (strCardNum, strDate, strTime)
frmShootInfo (the form I wish to open with the OpenForm macro)
contains the ID card number, dates, and times used to populate the
name-to-date table

The macro only has the one action, the OpenForm, with the where condition as
you said to enter it above. It still acts as if it cannot find the
information to use to filter the results.

Does this help a little more? Thanks for the help already, btw!
tina said:
well, on reading your original post again, it sounds like you have FormA
open. you also have FormB open, and FormB has a subform in it. you want to
refer to controls within the subform that's on FormB - to filter records on
FormA.

assuming that the command button is on the subform itself (not on FormB),
try the following syntax, as

[strCardNum]=[strCardNum] And [strShootDate]=[strDate] And
[strShootTime]=[strTime]

if the command button is on FormB (not on the subform itself), then try

[strCardNum]=[frmNameSelect].Form![strCardNum] And
[strShootDate]=[frmNameSelect].Form![strDate] And
[strShootTime]=[frmNameSelect].Form![strTime]

the above syntax also assumes that the name of the *subform CONTROL* in
FormB is [frmNameSelect]. you need to double check, because sometimes the
name of a subform object in the database window is NOT the same as the name
of the subform control in the main form.

to check the subform control name in FormB: open the form in design view,
and click on the subform (within FormB's design view) ONCE to select it. in
the Properties box, click on the Other tab and look at the Name property.

hth


Mark said:
Macro is very simple, just an OpenForm with no conditional statements.
It
is
set to the OnClick event for a button. The only argument is the Where
Condition, which is as follows:

[strCardNum]=[Forms]![frmNameSelect]![strCardNum] And
[strShootDate]=[Forms]![frmNameSelect]![strDate] And
[strShootTime]=[Forms]![frmNameSelect]![strTime]

where [frmNameSelect] is my subform, which is in a form named frmPersonalInfo.

If frmNameSelect is opened on its own, the macro works like a charm.
If
the
button is clicked in the subform (when frmPersonalInfo is opened), it
acts
as
if it can't find the fields in frmNameSelect, pulling up a dialog box
for
me
to enter the information.

:

the problem probably has to do with control references. what are the macro
Condition(s), Action(s), and ActionArguments for each action?


I'm trying to write a macro that selects a certain record in Form A
depending
on the contents of fields in a subform. We'll say the subform is
in
Form
B.
If I open the subform as its own seperate form and run the macro, it
functions properly. If I attempt to run the macro from the
subform
(set
to
OnClick on a button), it acts like it can't find the contents of the
field.
Any suggestions?
 
I'm having the same problem too.

Source subform is called "prop-use subform"
common field between subform and the target is "prop-number" (long integer)
Target form I'm trying to open is called "propdetails"

Consulted an old access book that had a few paragraphs about referencing
subforms but even that didn't work, when I "double-click" on the field entry
for the prop I wanted details on, access asks me to type the prop number in
by hand and then with that keyed in it then proceeds to open the propdetails
form. It shouldn't have asked me to type anything in.

tina said:
based on everything you've told me,

[strCardNum]=[strCardNum] And [strShootDate]=[strDate] And
[strShootTime]=[strTime]

should work. that's assuming that the names on the *left* side of each "="
pair are the correct names of the fields in in the RecordSource of
frmShootInfo; and the names on the *right* side of each "=" pair are the
correct names of the controls in the subform.

but it seems like people have more trouble getting control references to
work in macros, especially when subforms are involved. at this point, i'd
just throw up my hands and do it in VBA. again, if the command button is on
the subform (the location where a code, or macro, is called from makes a big
difference), add the following code to the button's Click event procedure,
as

DoCmd.OpenForm "frmShootInfo ", , , "strCardNum = '" _
& Me!strCardNum & "' And strShootDate = '" _
& Me!strDate & "' And strShootTime = '" & strTime & "'"

since all the fields are prefixed with "str", the above handles them all as
Text data types. if a field is a Number data type, the correct syntax would
leave off the single quotes, as

"strCardNum = " & Me!strCardNum

if a field is a Date/Time data type, the correct syntax would replace the
single quotes with the # sign, as

strShootDate = #" & Me!strDate & "#

if you don't know how to create an event procedure to house the code, post
back and i'll walk you through it, it's not hard.

hth


Mark said:
Still not working. :/ Let me list all the parts of the problem.

3 forms:
frmPersonalInfo (the main form)
main information pulled from here is the ID Card Number (strCardNum)
frmNameSelect (the sub-form, in frmPersonalInfo)
pulls information from a name-to-date table, listing ID card numbers,
dates, and times (strCardNum, strDate, strTime)
frmShootInfo (the form I wish to open with the OpenForm macro)
contains the ID card number, dates, and times used to populate the
name-to-date table

The macro only has the one action, the OpenForm, with the where condition as
you said to enter it above. It still acts as if it cannot find the
information to use to filter the results.

Does this help a little more? Thanks for the help already, btw!
tina said:
well, on reading your original post again, it sounds like you have FormA
open. you also have FormB open, and FormB has a subform in it. you want to
refer to controls within the subform that's on FormB - to filter records on
FormA.

assuming that the command button is on the subform itself (not on FormB),
try the following syntax, as

[strCardNum]=[strCardNum] And [strShootDate]=[strDate] And
[strShootTime]=[strTime]

if the command button is on FormB (not on the subform itself), then try

[strCardNum]=[frmNameSelect].Form![strCardNum] And
[strShootDate]=[frmNameSelect].Form![strDate] And
[strShootTime]=[frmNameSelect].Form![strTime]

the above syntax also assumes that the name of the *subform CONTROL* in
FormB is [frmNameSelect]. you need to double check, because sometimes the
name of a subform object in the database window is NOT the same as the name
of the subform control in the main form.

to check the subform control name in FormB: open the form in design view,
and click on the subform (within FormB's design view) ONCE to select it. in
the Properties box, click on the Other tab and look at the Name property.

hth


Macro is very simple, just an OpenForm with no conditional statements. It
is
set to the OnClick event for a button. The only argument is the Where
Condition, which is as follows:

[strCardNum]=[Forms]![frmNameSelect]![strCardNum] And
[strShootDate]=[Forms]![frmNameSelect]![strDate] And
[strShootTime]=[Forms]![frmNameSelect]![strTime]

where [frmNameSelect] is my subform, which is in a form named
frmPersonalInfo.

If frmNameSelect is opened on its own, the macro works like a charm. If
the
button is clicked in the subform (when frmPersonalInfo is opened), it acts
as
if it can't find the fields in frmNameSelect, pulling up a dialog box for
me
to enter the information.

:

the problem probably has to do with control references. what are the
macro
Condition(s), Action(s), and ActionArguments for each action?


I'm trying to write a macro that selects a certain record in Form A
depending
on the contents of fields in a subform. We'll say the subform is in
Form
B.
If I open the subform as its own seperate form and run the macro, it
functions properly. If I attempt to run the macro from the subform
(set
to
OnClick on a button), it acts like it can't find the contents of the
field.
Any suggestions?
 
are you filtering the data in the popup form from the command button's code?
or from the popup form's code? or from the popup form's underlying query?
also, please post the code, or the query criteria.


krazy darcy said:
I'm having the same problem too.

Source subform is called "prop-use subform"
common field between subform and the target is "prop-number" (long integer)
Target form I'm trying to open is called "propdetails"

Consulted an old access book that had a few paragraphs about referencing
subforms but even that didn't work, when I "double-click" on the field entry
for the prop I wanted details on, access asks me to type the prop number in
by hand and then with that keyed in it then proceeds to open the propdetails
form. It shouldn't have asked me to type anything in.

tina said:
based on everything you've told me,

[strCardNum]=[strCardNum] And [strShootDate]=[strDate] And
[strShootTime]=[strTime]

should work. that's assuming that the names on the *left* side of each "="
pair are the correct names of the fields in in the RecordSource of
frmShootInfo; and the names on the *right* side of each "=" pair are the
correct names of the controls in the subform.

but it seems like people have more trouble getting control references to
work in macros, especially when subforms are involved. at this point, i'd
just throw up my hands and do it in VBA. again, if the command button is on
the subform (the location where a code, or macro, is called from makes a big
difference), add the following code to the button's Click event procedure,
as

DoCmd.OpenForm "frmShootInfo ", , , "strCardNum = '" _
& Me!strCardNum & "' And strShootDate = '" _
& Me!strDate & "' And strShootTime = '" & strTime & "'"

since all the fields are prefixed with "str", the above handles them all as
Text data types. if a field is a Number data type, the correct syntax would
leave off the single quotes, as

"strCardNum = " & Me!strCardNum

if a field is a Date/Time data type, the correct syntax would replace the
single quotes with the # sign, as

strShootDate = #" & Me!strDate & "#

if you don't know how to create an event procedure to house the code, post
back and i'll walk you through it, it's not hard.

hth


Mark said:
Still not working. :/ Let me list all the parts of the problem.

3 forms:
frmPersonalInfo (the main form)
main information pulled from here is the ID Card Number (strCardNum)
frmNameSelect (the sub-form, in frmPersonalInfo)
pulls information from a name-to-date table, listing ID card numbers,
dates, and times (strCardNum, strDate, strTime)
frmShootInfo (the form I wish to open with the OpenForm macro)
contains the ID card number, dates, and times used to populate the
name-to-date table

The macro only has the one action, the OpenForm, with the where
condition
as
you said to enter it above. It still acts as if it cannot find the
information to use to filter the results.

Does this help a little more? Thanks for the help already, btw!
:

well, on reading your original post again, it sounds like you have FormA
open. you also have FormB open, and FormB has a subform in it. you
want
to
refer to controls within the subform that's on FormB - to filter
records
on
FormA.

assuming that the command button is on the subform itself (not on FormB),
try the following syntax, as

[strCardNum]=[strCardNum] And [strShootDate]=[strDate] And
[strShootTime]=[strTime]

if the command button is on FormB (not on the subform itself), then try

[strCardNum]=[frmNameSelect].Form![strCardNum] And
[strShootDate]=[frmNameSelect].Form![strDate] And
[strShootTime]=[frmNameSelect].Form![strTime]

the above syntax also assumes that the name of the *subform CONTROL* in
FormB is [frmNameSelect]. you need to double check, because
sometimes
the
name of a subform object in the database window is NOT the same as
the
name
of the subform control in the main form.

to check the subform control name in FormB: open the form in design view,
and click on the subform (within FormB's design view) ONCE to select
it.
in
the Properties box, click on the Other tab and look at the Name property.

hth


Macro is very simple, just an OpenForm with no conditional
statements.
It
is
set to the OnClick event for a button. The only argument is the Where
Condition, which is as follows:

[strCardNum]=[Forms]![frmNameSelect]![strCardNum] And
[strShootDate]=[Forms]![frmNameSelect]![strDate] And
[strShootTime]=[Forms]![frmNameSelect]![strTime]

where [frmNameSelect] is my subform, which is in a form named
frmPersonalInfo.

If frmNameSelect is opened on its own, the macro works like a
charm.
If
the
button is clicked in the subform (when frmPersonalInfo is opened),
it
acts
as
if it can't find the fields in frmNameSelect, pulling up a dialog
box
for
me
to enter the information.

:

the problem probably has to do with control references. what are the
macro
Condition(s), Action(s), and ActionArguments for each action?


I'm trying to write a macro that selects a certain record in
Form
A
depending
on the contents of fields in a subform. We'll say the subform
is
in
Form
B.
If I open the subform as its own seperate form and run the
macro,
it
functions properly. If I attempt to run the macro from the subform
(set
to
OnClick on a button), it acts like it can't find the contents
of
the
field.
Any suggestions?
 
(Sorry, just got home)

Here is the macro settings that I was originally trying:

Command = OpenForm
(the command's settings)
view = Form
filter name =
where condition =
[Forms]![Artworksdetails]![RelativesSub].[Form]![prop-number]
window mode = normal

The cousin to this macro works when I have the prop used subform open on
it's own (not as a subform) but not when it's a subform

The where condition was effectivly filtering on the prop-number field on
the basis of is-equal-to , and it opens the form propdetails which shows the
matching record for the prop-number you double-clicked on

I have used similar macro's elsewhere but not being launched from subforms.

This macro was assigned to the "double-click" event of the control of the
form that actually contains (when displayed in the form) the prop-number
data, and the form is continuous - so it shows all records that match the
specified record-number of the parent. (the subform works in that it shows
only the prop-numbers that have matching record-numbers that match with the
parent form)

What the macro does is opens the prop details form and shows the record with
the same prop-number as the record in which you double-clicked on.


i can't program but tried to adapt the script you gave Mark for my purposes
and unsurprisingly it didn't work (due to my adaptation)

tina said:
are you filtering the data in the popup form from the command button's code?
or from the popup form's code? or from the popup form's underlying query?
also, please post the code, or the query criteria.


krazy darcy said:
I'm having the same problem too.

Source subform is called "prop-use subform"
common field between subform and the target is "prop-number" (long integer)
Target form I'm trying to open is called "propdetails"

Consulted an old access book that had a few paragraphs about referencing
subforms but even that didn't work, when I "double-click" on the field entry
for the prop I wanted details on, access asks me to type the prop number in
by hand and then with that keyed in it then proceeds to open the propdetails
form. It shouldn't have asked me to type anything in.

tina said:
based on everything you've told me,

[strCardNum]=[strCardNum] And [strShootDate]=[strDate] And
[strShootTime]=[strTime]

should work. that's assuming that the names on the *left* side of each "="
pair are the correct names of the fields in in the RecordSource of
frmShootInfo; and the names on the *right* side of each "=" pair are the
correct names of the controls in the subform.

but it seems like people have more trouble getting control references to
work in macros, especially when subforms are involved. at this point, i'd
just throw up my hands and do it in VBA. again, if the command button is on
the subform (the location where a code, or macro, is called from makes a big
difference), add the following code to the button's Click event procedure,
as

DoCmd.OpenForm "frmShootInfo ", , , "strCardNum = '" _
& Me!strCardNum & "' And strShootDate = '" _
& Me!strDate & "' And strShootTime = '" & strTime & "'"

since all the fields are prefixed with "str", the above handles them all as
Text data types. if a field is a Number data type, the correct syntax would
leave off the single quotes, as

"strCardNum = " & Me!strCardNum

if a field is a Date/Time data type, the correct syntax would replace the
single quotes with the # sign, as

strShootDate = #" & Me!strDate & "#

if you don't know how to create an event procedure to house the code, post
back and i'll walk you through it, it's not hard.

hth


Still not working. :/ Let me list all the parts of the problem.

3 forms:
frmPersonalInfo (the main form)
main information pulled from here is the ID Card Number (strCardNum)
frmNameSelect (the sub-form, in frmPersonalInfo)
pulls information from a name-to-date table, listing ID card numbers,
dates, and times (strCardNum, strDate, strTime)
frmShootInfo (the form I wish to open with the OpenForm macro)
contains the ID card number, dates, and times used to populate the
name-to-date table

The macro only has the one action, the OpenForm, with the where condition
as
you said to enter it above. It still acts as if it cannot find the
information to use to filter the results.

Does this help a little more? Thanks for the help already, btw!
:

well, on reading your original post again, it sounds like you have FormA
open. you also have FormB open, and FormB has a subform in it. you want
to
refer to controls within the subform that's on FormB - to filter records
on
FormA.

assuming that the command button is on the subform itself (not on
FormB),
try the following syntax, as

[strCardNum]=[strCardNum] And [strShootDate]=[strDate] And
[strShootTime]=[strTime]

if the command button is on FormB (not on the subform itself), then try

[strCardNum]=[frmNameSelect].Form![strCardNum] And
[strShootDate]=[frmNameSelect].Form![strDate] And
[strShootTime]=[frmNameSelect].Form![strTime]

the above syntax also assumes that the name of the *subform CONTROL* in
FormB is [frmNameSelect]. you need to double check, because sometimes
the
name of a subform object in the database window is NOT the same as the
name
of the subform control in the main form.

to check the subform control name in FormB: open the form in design
view,
and click on the subform (within FormB's design view) ONCE to select it.
in
the Properties box, click on the Other tab and look at the Name
property.

hth


Macro is very simple, just an OpenForm with no conditional statements.
It
is
set to the OnClick event for a button. The only argument is the Where
Condition, which is as follows:

[strCardNum]=[Forms]![frmNameSelect]![strCardNum] And
[strShootDate]=[Forms]![frmNameSelect]![strDate] And
[strShootTime]=[Forms]![frmNameSelect]![strTime]

where [frmNameSelect] is my subform, which is in a form named
frmPersonalInfo.

If frmNameSelect is opened on its own, the macro works like a charm.
If
the
button is clicked in the subform (when frmPersonalInfo is opened), it
acts
as
if it can't find the fields in frmNameSelect, pulling up a dialog box
for
me
to enter the information.

:

the problem probably has to do with control references. what are the
macro
Condition(s), Action(s), and ActionArguments for each action?


I'm trying to write a macro that selects a certain record in Form
A
depending
on the contents of fields in a subform. We'll say the subform is
in
Form
B.
If I open the subform as its own seperate form and run the macro,
it
functions properly. If I attempt to run the macro from the
subform
(set
to
OnClick on a button), it acts like it can't find the contents of
the
field.
Any suggestions?
 
if you want to post the VBA code you tried, and tell me what is the Data
Type of each field referenced in the code, i'll see if i can help you with
it.

hth


krazy darcy said:
(Sorry, just got home)

Here is the macro settings that I was originally trying:

Command = OpenForm
(the command's settings)
view = Form
filter name =
where condition =
[Forms]![Artworksdetails]![RelativesSub].[Form]![prop-number]
window mode = normal

The cousin to this macro works when I have the prop used subform open on
it's own (not as a subform) but not when it's a subform

The where condition was effectivly filtering on the prop-number field on
the basis of is-equal-to , and it opens the form propdetails which shows the
matching record for the prop-number you double-clicked on

I have used similar macro's elsewhere but not being launched from subforms.

This macro was assigned to the "double-click" event of the control of the
form that actually contains (when displayed in the form) the prop-number
data, and the form is continuous - so it shows all records that match the
specified record-number of the parent. (the subform works in that it shows
only the prop-numbers that have matching record-numbers that match with the
parent form)

What the macro does is opens the prop details form and shows the record with
the same prop-number as the record in which you double-clicked on.


i can't program but tried to adapt the script you gave Mark for my purposes
and unsurprisingly it didn't work (due to my adaptation)

tina said:
are you filtering the data in the popup form from the command button's code?
or from the popup form's code? or from the popup form's underlying query?
also, please post the code, or the query criteria.


krazy darcy said:
I'm having the same problem too.

Source subform is called "prop-use subform"
common field between subform and the target is "prop-number" (long integer)
Target form I'm trying to open is called "propdetails"

Consulted an old access book that had a few paragraphs about referencing
subforms but even that didn't work, when I "double-click" on the field entry
for the prop I wanted details on, access asks me to type the prop
number
in
by hand and then with that keyed in it then proceeds to open the propdetails
form. It shouldn't have asked me to type anything in.

:

based on everything you've told me,

[strCardNum]=[strCardNum] And [strShootDate]=[strDate] And
[strShootTime]=[strTime]

should work. that's assuming that the names on the *left* side of
each
"="
pair are the correct names of the fields in in the RecordSource of
frmShootInfo; and the names on the *right* side of each "=" pair are the
correct names of the controls in the subform.

but it seems like people have more trouble getting control references to
work in macros, especially when subforms are involved. at this
point,
i'd
just throw up my hands and do it in VBA. again, if the command
button is
on
the subform (the location where a code, or macro, is called from
makes a
big
difference), add the following code to the button's Click event procedure,
as

DoCmd.OpenForm "frmShootInfo ", , , "strCardNum = '" _
& Me!strCardNum & "' And strShootDate = '" _
& Me!strDate & "' And strShootTime = '" & strTime & "'"

since all the fields are prefixed with "str", the above handles them
all
as
Text data types. if a field is a Number data type, the correct
syntax
would
leave off the single quotes, as

"strCardNum = " & Me!strCardNum

if a field is a Date/Time data type, the correct syntax would
replace
the
single quotes with the # sign, as

strShootDate = #" & Me!strDate & "#

if you don't know how to create an event procedure to house the
code,
post
back and i'll walk you through it, it's not hard.

hth


Still not working. :/ Let me list all the parts of the problem.

3 forms:
frmPersonalInfo (the main form)
main information pulled from here is the ID Card Number (strCardNum)
frmNameSelect (the sub-form, in frmPersonalInfo)
pulls information from a name-to-date table, listing ID card numbers,
dates, and times (strCardNum, strDate, strTime)
frmShootInfo (the form I wish to open with the OpenForm macro)
contains the ID card number, dates, and times used to populate the
name-to-date table

The macro only has the one action, the OpenForm, with the where condition
as
you said to enter it above. It still acts as if it cannot find the
information to use to filter the results.

Does this help a little more? Thanks for the help already, btw!
:

well, on reading your original post again, it sounds like you
have
FormA
open. you also have FormB open, and FormB has a subform in it.
you
want
to
refer to controls within the subform that's on FormB - to filter records
on
FormA.

assuming that the command button is on the subform itself (not on
FormB),
try the following syntax, as

[strCardNum]=[strCardNum] And [strShootDate]=[strDate] And
[strShootTime]=[strTime]

if the command button is on FormB (not on the subform itself),
then
try
[strCardNum]=[frmNameSelect].Form![strCardNum] And
[strShootDate]=[frmNameSelect].Form![strDate] And
[strShootTime]=[frmNameSelect].Form![strTime]

the above syntax also assumes that the name of the *subform
CONTROL*
in
FormB is [frmNameSelect]. you need to double check, because sometimes
the
name of a subform object in the database window is NOT the same
as
the
name
of the subform control in the main form.

to check the subform control name in FormB: open the form in design
view,
and click on the subform (within FormB's design view) ONCE to
select
it.
in
the Properties box, click on the Other tab and look at the Name
property.

hth


Macro is very simple, just an OpenForm with no conditional statements.
It
is
set to the OnClick event for a button. The only argument is
the
Where
Condition, which is as follows:

[strCardNum]=[Forms]![frmNameSelect]![strCardNum] And
[strShootDate]=[Forms]![frmNameSelect]![strDate] And
[strShootTime]=[Forms]![frmNameSelect]![strTime]

where [frmNameSelect] is my subform, which is in a form named
frmPersonalInfo.

If frmNameSelect is opened on its own, the macro works like a charm.
If
the
button is clicked in the subform (when frmPersonalInfo is
opened),
it
acts
as
if it can't find the fields in frmNameSelect, pulling up a
dialog
box
for
me
to enter the information.

:

the problem probably has to do with control references. what
are
the
macro
Condition(s), Action(s), and ActionArguments for each action?


I'm trying to write a macro that selects a certain record
in
Form
A
depending
on the contents of fields in a subform. We'll say the
subform
is
in
Form
B.
If I open the subform as its own seperate form and run the macro,
it
functions properly. If I attempt to run the macro from the
subform
(set
to
OnClick on a button), it acts like it can't find the
contents
of
the
field.
Any suggestions?
 
Krazy,

The Where Condition argument in the macro is incomplete. It will need
to be something like this...

[prop-number]=[Forms]![Artworksdetails]![RelativesSub].[Form]![prop-number]
 
Here is my code
This is the "event procedure" assigned to the double-click on the field.
It's probably some small typo that a programmer would spot a mile away
that's stopping it from working.

Private Sub prop_number_DblClick(Cancel As Integer)
DoCmd.OpenForm "propdetails", , , "prop-number" = "Me!prop-number"
End Sub

Thanks.

tina said:
if you want to post the VBA code you tried, and tell me what is the Data
Type of each field referenced in the code, i'll see if i can help you with
it.

hth


krazy darcy said:
(Sorry, just got home)

Here is the macro settings that I was originally trying:

Command = OpenForm
(the command's settings)
view = Form
filter name =
where condition =
[Forms]![Artworksdetails]![RelativesSub].[Form]![prop-number]
window mode = normal

The cousin to this macro works when I have the prop used subform open on
it's own (not as a subform) but not when it's a subform

The where condition was effectivly filtering on the prop-number field on
the basis of is-equal-to , and it opens the form propdetails which shows the
matching record for the prop-number you double-clicked on

I have used similar macro's elsewhere but not being launched from subforms.

This macro was assigned to the "double-click" event of the control of the
form that actually contains (when displayed in the form) the prop-number
data, and the form is continuous - so it shows all records that match the
specified record-number of the parent. (the subform works in that it shows
only the prop-numbers that have matching record-numbers that match with the
parent form)

What the macro does is opens the prop details form and shows the record with
the same prop-number as the record in which you double-clicked on.


i can't program but tried to adapt the script you gave Mark for my purposes
and unsurprisingly it didn't work (due to my adaptation)

tina said:
are you filtering the data in the popup form from the command button's code?
or from the popup form's code? or from the popup form's underlying query?
also, please post the code, or the query criteria.


I'm having the same problem too.

Source subform is called "prop-use subform"
common field between subform and the target is "prop-number" (long
integer)
Target form I'm trying to open is called "propdetails"

Consulted an old access book that had a few paragraphs about referencing
subforms but even that didn't work, when I "double-click" on the field
entry
for the prop I wanted details on, access asks me to type the prop number
in
by hand and then with that keyed in it then proceeds to open the
propdetails
form. It shouldn't have asked me to type anything in.

:

based on everything you've told me,

[strCardNum]=[strCardNum] And [strShootDate]=[strDate] And
[strShootTime]=[strTime]

should work. that's assuming that the names on the *left* side of each
"="
pair are the correct names of the fields in in the RecordSource of
frmShootInfo; and the names on the *right* side of each "=" pair are the
correct names of the controls in the subform.

but it seems like people have more trouble getting control references to
work in macros, especially when subforms are involved. at this point,
i'd
just throw up my hands and do it in VBA. again, if the command button is
on
the subform (the location where a code, or macro, is called from makes a
big
difference), add the following code to the button's Click event
procedure,
as

DoCmd.OpenForm "frmShootInfo ", , , "strCardNum = '" _
& Me!strCardNum & "' And strShootDate = '" _
& Me!strDate & "' And strShootTime = '" & strTime & "'"

since all the fields are prefixed with "str", the above handles them all
as
Text data types. if a field is a Number data type, the correct syntax
would
leave off the single quotes, as

"strCardNum = " & Me!strCardNum

if a field is a Date/Time data type, the correct syntax would replace
the
single quotes with the # sign, as

strShootDate = #" & Me!strDate & "#

if you don't know how to create an event procedure to house the code,
post
back and i'll walk you through it, it's not hard.

hth


Still not working. :/ Let me list all the parts of the problem.

3 forms:
frmPersonalInfo (the main form)
main information pulled from here is the ID Card Number
(strCardNum)
frmNameSelect (the sub-form, in frmPersonalInfo)
pulls information from a name-to-date table, listing ID card
numbers,
dates, and times (strCardNum, strDate, strTime)
frmShootInfo (the form I wish to open with the OpenForm macro)
contains the ID card number, dates, and times used to populate the
name-to-date table

The macro only has the one action, the OpenForm, with the where
condition
as
you said to enter it above. It still acts as if it cannot find the
information to use to filter the results.

Does this help a little more? Thanks for the help already, btw!
:

well, on reading your original post again, it sounds like you have
FormA
open. you also have FormB open, and FormB has a subform in it. you
want
to
refer to controls within the subform that's on FormB - to filter
records
on
FormA.

assuming that the command button is on the subform itself (not on
FormB),
try the following syntax, as

[strCardNum]=[strCardNum] And [strShootDate]=[strDate] And
[strShootTime]=[strTime]

if the command button is on FormB (not on the subform itself), then
try

[strCardNum]=[frmNameSelect].Form![strCardNum] And
[strShootDate]=[frmNameSelect].Form![strDate] And
[strShootTime]=[frmNameSelect].Form![strTime]

the above syntax also assumes that the name of the *subform CONTROL*
in
FormB is [frmNameSelect]. you need to double check, because
sometimes
the
name of a subform object in the database window is NOT the same as
the
name
of the subform control in the main form.

to check the subform control name in FormB: open the form in design
view,
and click on the subform (within FormB's design view) ONCE to select
it.
in
the Properties box, click on the Other tab and look at the Name
property.

hth


Macro is very simple, just an OpenForm with no conditional
statements.
It
is
set to the OnClick event for a button. The only argument is the
Where
Condition, which is as follows:

[strCardNum]=[Forms]![frmNameSelect]![strCardNum] And
[strShootDate]=[Forms]![frmNameSelect]![strDate] And
[strShootTime]=[Forms]![frmNameSelect]![strTime]

where [frmNameSelect] is my subform, which is in a form named
frmPersonalInfo.

If frmNameSelect is opened on its own, the macro works like a
charm.
If
the
button is clicked in the subform (when frmPersonalInfo is opened),
it
acts
as
if it can't find the fields in frmNameSelect, pulling up a dialog
box
for
me
to enter the information.

:

the problem probably has to do with control references. what are
the
macro
Condition(s), Action(s), and ActionArguments for each action?


I'm trying to write a macro that selects a certain record in
Form
A
depending
on the contents of fields in a subform. We'll say the subform
is
in
Form
B.
If I open the subform as its own seperate form and run the
macro,
it
functions properly. If I attempt to run the macro from the
subform
(set
to
OnClick on a button), it acts like it can't find the contents
of
the
field.
Any suggestions?
 
Krazy,

Very similar to the mistake you made with the macro Where Condirion.
There is a problem with the Where Condition in the code. Try it like
this...
DoCmd.OpenForm "propdetails", , , "[prop-number]=" & Me!prop-number
 
Thanks very much.

It appears part of the problem was in my field name "prop-number"
when I pasted the code you provided me with and then saved, it appeared upon
re-opening the code as:

& Me!prop - number

So I went through the relavant tables, queries, forms, macros/code and
relationships to change "prop-number" to "propnumber". It didn't seem to
like the "-" in the fieldname on the end of the code.

It is going now.

Thanks very much.

Steve Schapel said:
Krazy,

Very similar to the mistake you made with the macro Where Condirion.
There is a problem with the Where Condition in the code. Try it like
this...
DoCmd.OpenForm "propdetails", , , "[prop-number]=" & Me!prop-number

--
Steve Schapel, Microsoft Access MVP

krazy said:
Here is my code
This is the "event procedure" assigned to the double-click on the field.
It's probably some small typo that a programmer would spot a mile away
that's stopping it from working.

Private Sub prop_number_DblClick(Cancel As Integer)
DoCmd.OpenForm "propdetails", , , "prop-number" = "Me!prop-number"
End Sub

Thanks.
 
Back
Top