filtering a form re-visited

J

johnlute

I posted this in a previous question which quickly became ugly so I
thought I'd start over. When I remove "strCriteria" from this line:

DoCmd.OpenForm strFormToOpen, acNormal,
strCriteria

then [frmPackaging] opens but NOT filtered. If I leave "strCriteria"
in the line then [frmPackaging] does NOT open.

Does anyone see what's wrong with my strCriteria?

Thanks for you time!

Private Sub cbMainSelect_AfterUpdate()
Dim strFormToOpen As String
Dim strCriteria As String
strCriteria = "Forms![frmPackaging].Form![cbqryTypes] = Forms!
[KEYSTONEeditids].Form![cbMainSelect].Column(2)"

With Me!cbMainSelect
'If no selection has been made, we can't do anything useful.
If IsNull(.Value) Then
Exit Sub
End If

'Here a selection has been made, so open the appropriate form
'for the selection.

'Lookup the form, returning a null string if none is
specified.
strFormToOpen = vbNullString & _
DLookup("FormToOpen", "tblProfileTypes", _
"txtProfileType=""" & .Column(2) & """")
If Me.cbMainSelect.Column(1) = "PK" Then
DoCmd.OpenForm strFormToOpen, acNormal,
strCriteria
End If
DoCmd.OpenForm strFormToOpen, acNormal

End With

End Sub
 
R

Rob Parker

strCriteria needs to contain a valid filter string, not a string containing
the place where a value can be found. I don't know what the name of the
field you're trying to filter on is, or its datatype, so I can't give you an
exact answer, but the line which sets the value for strCriteria should be
something like:

strCriteria = "FieldName = " & Forms![frmPackaging].Form![cbqryTypes] =
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2)

if the field is a numeric datatype, or

strCriteria = "FieldName = """ & Forms![frmPackaging].Form![cbqryTypes]
= Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2) & """"

if the field is a text datatype.

HTH,

Rob
 
J

johnlute

Hi, Rob.

Thanks for the reply.
strCriteria needs to contain a valid filter string, not a string containing
the place where a value can be found.  I don't know what the name of the
field you're trying to filter on is,

Maybe this is my problem. I'm trying to open a form with its control
[cbqrytypes] filtered to the value in [cbMainSelect].Column(2). The
fields are text data types. [cbqrytypes] happens to be unbound as is
[cbMainSelect].
    strCriteria = "FieldName = """ & Forms![frmPackaging].Form! [cbqryTypes]
= Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2) & """"

OK. But I'm not clear on what I need for "FieldName". I believe I've
claimed all of the pertinent fields and controls...?
 
R

Rob Parker

Hi John,

I'm afraid I don't really understand exactly what you're trying to do. Or
perhaps, you're not understanding Access well enough to describe your
problem.

You say "I'm trying to open a form with its control [cbqrytypes] filtered
...." which rather confuses me. The DoCmd.OpenForm statement, when supplied
with a Where parameter (in this case, your strCriteria), will open the
specified form (in this case, the form given by strFormToOpen) with its
RecordSource filtered by strCriteria.

I don't understand what you mean by "... its control [cbqrytypes] ...". Are
you meaning that the value of [cbqrytypes] (whatever [cbqrytypes] is - this
syntax generally refers to a field name) is the RecordSource for your form
which is opening? Or does [cbqrytypes] contain the name of a control on the
form you are opening - a combobox, perhaps - and are you trying to set its
RecordSource to something filtered by the selection in the unbound
cbMainSelect control on your current form when you open the form?

Clarification needed before I can assist further,

Rob


Hi, Rob.

Thanks for the reply.
strCriteria needs to contain a valid filter string, not a string
containing
the place where a value can be found. I don't know what the name of the
field you're trying to filter on is,

Maybe this is my problem. I'm trying to open a form with its control
[cbqrytypes] filtered to the value in [cbMainSelect].Column(2). The
fields are text data types. [cbqrytypes] happens to be unbound as is
[cbMainSelect].
strCriteria = "FieldName = """ & Forms![frmPackaging].Form! [cbqryTypes]
= Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2) & """"

OK. But I'm not clear on what I need for "FieldName". I believe I've
claimed all of the pertinent fields and controls...?
 
J

johnlute

I'm afraid I don't really understand exactly what you're trying to do.  Or
perhaps, you're not understanding Access well enough to describe your
problem.

It's both. And your not understanding is due to my ignorance :)
You say "I'm trying to open a form with its control [cbqrytypes] filtered
..." which rather confuses me.  The DoCmd.OpenForm statement, when supplied
with a Where parameter (in this case, your strCriteria), will open the
specified form (in this case, the form given by strFormToOpen) with its
RecordSource filtered by strCriteria.

This is something I've obviously never wrapped my brain around. Yes,
in this case the form given by strFormToOpen is what I'm trying to
open WITH its control [cbqrytypes] filtered to the value in [Forms!
[KEYSTONEeditids].Form![cbMainSelect].Column(2)
I don't understand what you mean by "... its control [cbqrytypes] ...".  Are
you meaning that the value of [cbqrytypes] (whatever [cbqrytypes] is - this
syntax generally refers to a field name) is the RecordSource for your form
which is opening?
No.

Or does [cbqrytypes] contain the name of a control on the
form you are opening - a combobox, perhaps - and are you trying to set its
RecordSource to something filtered by the selection in the unbound
cbMainSelect control on your current form when you open the form?

We're getting closer! [cbqrytypes] IS the control (a combobox) on the
form that I'm opening. It also serves as a filter for the form. Here's
the form's record source:

SELECT tblProfiles.*, tblProfiles.Type AS PKType
FROM tblProfiles
WHERE (((tblProfiles.Type)=[Forms]![frmPackaging].[Form]!
[cbqryTypes])) OR ((([Forms]![frmPackaging].[Form]![cbqryTypes]) Is
Null));

So...[frmPackaging]is opened from the "Main Menu" [KEYSTONEeditids]
via its control [cbMainSelect]. With the [frmPackaging] opened to the
filtered value AND upon editing the desired record - a user will want
to clear [cbqrytypes] OR make another selection to filter for another
group of entities.

Scenario: from the Main Menu a user selects "Cups" from
[cbMainSelect]. The "Cups" record has a "CP" value in the 2nd column
of [cbMainSelect] and a "PK" value in the 1st column of
[cbMainSelect]. So I'm trying to get [frmPackaging] to open and filter
to the "CP" value. After editing the desired Cup record(s) the user
wants to navigate to the "Glass Bottles" group so rather than closing
the form and going back to the Main Menu they simply select "BTGL"
from [cbqryTypes].

This may seem a bit nuts. I suppose the question would be: Why not
just have [cbMainSelect] list "Packaging" as a value to open
[frmPackaging] and then filter to whatever group a user wants? That
crossed my mind however, it's so much more user-friendly to list all
of the groups in [cbMainSelect] so that a user can open [frmPackaging]
to their desired group without having to think or remember to filter
it once they've opened it.

This is all on the heels of a major re-design. I'm now using a single
form for ALL packaging types. Previously I used ONE form for EACH
type. Whittling things down to one form is an enormous improvement
however it's created this challenge here. Here's more info on the re-
design:

http://groups.google.com/group/micr...1f8aead07?lnk=gst&q=johnlute#49365471f8aead07
Clarification needed before I can assist further,

I hope that helps! Sorry for the length. I couldn't find an easier way
to describe. As I've spelled it out it's become somewhat apparent that
I've got the wrong approach. I'm not sure however because I;m not real
clear on the trick of opening forms per a criteria.

Thanks for your help!
 
D

Douglas J. Steele

No offense, Rob, but

strCriteria = "FieldName = " & Forms![frmPackaging].Form![cbqryTypes] =
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2)

isn't a "valid filter string"

John: strCriteria needs to include the name of a field in the form's
underlying recordset in the quotes (followed by the equal sign, also in the
quotes), concatenated to the value to which the field is to be compared.

That means it needs to be something like

strCriteria = "FieldName = " &
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2)

or

strCriteria = "FieldName = """ &
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2) & """"

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Rob Parker said:
strCriteria needs to contain a valid filter string, not a string
containing the place where a value can be found. I don't know what the
name of the field you're trying to filter on is, or its datatype, so I
can't give you an exact answer, but the line which sets the value for
strCriteria should be something like:

strCriteria = "FieldName = " & Forms![frmPackaging].Form![cbqryTypes] =
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2)

if the field is a numeric datatype, or

strCriteria = "FieldName = """ & Forms![frmPackaging].Form![cbqryTypes]
= Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2) & """"

if the field is a text datatype.

HTH,

Rob

I posted this in a previous question which quickly became ugly so I
thought I'd start over. When I remove "strCriteria" from this line:

DoCmd.OpenForm strFormToOpen, acNormal,
strCriteria

then [frmPackaging] opens but NOT filtered. If I leave "strCriteria"
in the line then [frmPackaging] does NOT open.

Does anyone see what's wrong with my strCriteria?

Thanks for you time!

Private Sub cbMainSelect_AfterUpdate()
Dim strFormToOpen As String
Dim strCriteria As String
strCriteria = "Forms![frmPackaging].Form![cbqryTypes] = Forms!
[KEYSTONEeditids].Form![cbMainSelect].Column(2)"

With Me!cbMainSelect
'If no selection has been made, we can't do anything useful.
If IsNull(.Value) Then
Exit Sub
End If

'Here a selection has been made, so open the appropriate form
'for the selection.

'Lookup the form, returning a null string if none is
specified.
strFormToOpen = vbNullString & _
DLookup("FormToOpen", "tblProfileTypes", _
"txtProfileType=""" & .Column(2) & """")
If Me.cbMainSelect.Column(1) = "PK" Then
DoCmd.OpenForm strFormToOpen, acNormal,
strCriteria
End If
DoCmd.OpenForm strFormToOpen, acNormal

End With

End Sub
 
R

Rob Parker

Thanks for the catch, Doug.

I responded quickly, and simply put the expression John had into the
concatenated section of the expression - didn't notice that it was composed
of two parts, with an = between them.

But it turns out that strCriteria isn't really the problem that John is
wanting to solve. I've skimmed his follow-up and am thinking about the best
way to do what he wants, but won't get around to replying for a few hours
(other things to do first). If you'd like to take over please feel free.

Rob

No offense, Rob, but

strCriteria = "FieldName = " &
Forms![frmPackaging].Form![cbqryTypes] =
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2)
isn't a "valid filter string"

John: strCriteria needs to include the name of a field in the form's
underlying recordset in the quotes (followed by the equal sign, also
in the quotes), concatenated to the value to which the field is to be
compared.
That means it needs to be something like

strCriteria = "FieldName = " &
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2)

or

strCriteria = "FieldName = """ &
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2) & """"


Rob Parker said:
strCriteria needs to contain a valid filter string, not a string
containing the place where a value can be found. I don't know what
the name of the field you're trying to filter on is, or its
datatype, so I can't give you an exact answer, but the line which
sets the value for strCriteria should be something like:

strCriteria = "FieldName = " &
Forms![frmPackaging].Form![cbqryTypes] =
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2) if the field is a
numeric datatype, or

strCriteria = "FieldName = """ &
Forms![frmPackaging].Form![cbqryTypes] =
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2) & """" if the field
is a text datatype.

HTH,

Rob

I posted this in a previous question which quickly became ugly so I
thought I'd start over. When I remove "strCriteria" from this line:

DoCmd.OpenForm strFormToOpen, acNormal,
strCriteria

then [frmPackaging] opens but NOT filtered. If I leave "strCriteria"
in the line then [frmPackaging] does NOT open.

Does anyone see what's wrong with my strCriteria?

Thanks for you time!

Private Sub cbMainSelect_AfterUpdate()
Dim strFormToOpen As String
Dim strCriteria As String
strCriteria = "Forms![frmPackaging].Form![cbqryTypes] = Forms!
[KEYSTONEeditids].Form![cbMainSelect].Column(2)"

With Me!cbMainSelect
'If no selection has been made, we can't do anything useful.
If IsNull(.Value) Then
Exit Sub
End If

'Here a selection has been made, so open the appropriate form
'for the selection.

'Lookup the form, returning a null string if none is
specified.
strFormToOpen = vbNullString & _
DLookup("FormToOpen", "tblProfileTypes", _
"txtProfileType=""" & .Column(2) & """")
If Me.cbMainSelect.Column(1) = "PK" Then
DoCmd.OpenForm strFormToOpen, acNormal,
strCriteria
End If
DoCmd.OpenForm strFormToOpen, acNormal

End With

End Sub
 
J

johnlute

Thanks, Doug.

I tried both of those but the form ends up opening the entire record
set rather than filtered to the [cbMainSelect].Column(2) value.

I've tried this every which way and just can't get the form to open
properly.

UGH.

No offense, Rob, but

   strCriteria = "FieldName = " & Forms![frmPackaging].Form![cbqryTypes] =
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2)

isn't a "valid filter string"

John: strCriteria needs to include the name of a field in the form's
underlying recordset in the quotes (followed by the equal sign, also in the
quotes), concatenated to the value to which the field is to be compared.

That means it needs to be something like

   strCriteria = "FieldName = " &
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2)

or

   strCriteria = "FieldName = """ &
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2) & """"

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no private e-mails, please)




strCriteria needs to contain a valid filter string, not a string
containing the place where a value can be found.  I don't know what the
name of the field you're trying to filter on is, or its datatype, so I
can't give you an exact answer, but the line which sets the value for
strCriteria should be something like:
   strCriteria = "FieldName = " & Forms![frmPackaging].Form![cbqryTypes] =
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2)
if the field is a numeric datatype, or
   strCriteria = "FieldName = """ & Forms![frmPackaging].Form![cbqryTypes]
= Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2) & """"
if the field is a text datatype.

johnlute said:
I posted this in a previous question which quickly became ugly so I
thought I'd start over. When I remove "strCriteria" from this line:
DoCmd.OpenForm strFormToOpen, acNormal,
strCriteria
then [frmPackaging] opens but NOT filtered. If I leave "strCriteria"
in the line then [frmPackaging] does NOT open.
Does anyone see what's wrong with my strCriteria?
Thanks for you time!
Private Sub cbMainSelect_AfterUpdate()
Dim strFormToOpen As String
Dim strCriteria As String
strCriteria = "Forms![frmPackaging].Form![cbqryTypes] = Forms!
[KEYSTONEeditids].Form![cbMainSelect].Column(2)"
   With Me!cbMainSelect
       'If no selection has been made, we can't do anything useful.
       If IsNull(.Value) Then
           Exit Sub
       End If
       'Here a selection has been made, so open the appropriate form
       'for the selection.
       'Lookup the form, returning a null string if none is
specified.
       strFormToOpen = vbNullString & _
           DLookup("FormToOpen", "tblProfileTypes", _
                   "txtProfileType=""" & .Column(2) & """")
                   If Me.cbMainSelect.Column(1) = "PK" Then
                       DoCmd.OpenForm strFormToOpen, acNormal,
strCriteria
                   End If
           DoCmd.OpenForm strFormToOpen, acNormal
   End With
End Sub- Hide quoted text -

- Show quoted text -
 
J

johnlute

I've tried all of these and still no luck:

Private Sub cbMainSelect_AfterUpdate()
Dim strFormToOpen As String
Dim strCriteria As String

'FYI Forms![frmPackaging].Form![cbqryTypes] is a Text data type.

'The following open frmPackaging (either by hard code or per
strFormToOpen) to the entire recordset and do NOT filter the type:
'strCriteria = "Forms![frmPackaging].Form![cbqryTypes]" = "Forms!
[KEYSTONEeditids].Form![cbMainSelect].Column(2)"
'strCriteria = "cbqrytypes = " & Forms![KEYSTONEeditids].Form!
[cbMainSelect].Column(2)
'strCriteria = "cbqrytypes = """ & Forms![KEYSTONEeditids].Form!
[cbMainSelect].Column(2) & """"
'strCriteria = "Forms![frmPackaging].Form![cbqryTypes] = " &
Me.cbMainSelect.Column(2)
'strCriteria = "Forms![frmPackaging].Form![cbqryTypes] = Forms!
[KEYSTONEeditids].Form![cbMainSelect].Column(2)"

With Me!cbMainSelect
'If no selection has been made, we can't do anything useful.
If IsNull(.Value) Then
Exit Sub
End If

'Here a selection has been made, so open the appropriate form
'for the selection.

'Lookup the form, returning a null string if none is
specified.
strFormToOpen = vbNullString & _
DLookup("FormToOpen", "tblProfileTypes", _
"txtProfileType=""" & .Column(2) & """")
If Me.cbMainSelect.Column(1) = "PK" Then
DoCmd.OpenForm strFormToOpen, acNormal,
strCriteria
End If
DoCmd.OpenForm strFormToOpen, acNormal

End With

End Sub




No offense, Rob, but

   strCriteria = "FieldName = " & Forms![frmPackaging].Form![cbqryTypes] =
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2)

isn't a "valid filter string"

John: strCriteria needs to include the name of a field in the form's
underlying recordset in the quotes (followed by the equal sign, also in the
quotes), concatenated to the value to which the field is to be compared.

That means it needs to be something like

   strCriteria = "FieldName = " &
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2)

or

   strCriteria = "FieldName = """ &
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2) & """"

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no private e-mails, please)




strCriteria needs to contain a valid filter string, not a string
containing the place where a value can be found.  I don't know what the
name of the field you're trying to filter on is, or its datatype, so I
can't give you an exact answer, but the line which sets the value for
strCriteria should be something like:
   strCriteria = "FieldName = " & Forms![frmPackaging].Form![cbqryTypes] =
Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2)
if the field is a numeric datatype, or
   strCriteria = "FieldName = """ & Forms![frmPackaging].Form![cbqryTypes]
= Forms![KEYSTONEeditids].Form![cbMainSelect].Column(2) & """"
if the field is a text datatype.

johnlute said:
I posted this in a previous question which quickly became ugly so I
thought I'd start over. When I remove "strCriteria" from this line:
DoCmd.OpenForm strFormToOpen, acNormal,
strCriteria
then [frmPackaging] opens but NOT filtered. If I leave "strCriteria"
in the line then [frmPackaging] does NOT open.
Does anyone see what's wrong with my strCriteria?
Thanks for you time!
Private Sub cbMainSelect_AfterUpdate()
Dim strFormToOpen As String
Dim strCriteria As String
strCriteria = "Forms![frmPackaging].Form![cbqryTypes] = Forms!
[KEYSTONEeditids].Form![cbMainSelect].Column(2)"
   With Me!cbMainSelect
       'If no selection has been made, we can't do anything useful.
       If IsNull(.Value) Then
           Exit Sub
       End If
       'Here a selection has been made, so open the appropriate form
       'for the selection.
       'Lookup the form, returning a null string if none is
specified.
       strFormToOpen = vbNullString & _
           DLookup("FormToOpen", "tblProfileTypes", _
                   "txtProfileType=""" & .Column(2) & """")
                   If Me.cbMainSelect.Column(1) = "PK" Then
                       DoCmd.OpenForm strFormToOpen, acNormal,
strCriteria
                   End If
           DoCmd.OpenForm strFormToOpen, acNormal
   End With
End Sub- Hide quoted text -

- Show quoted text -
 
R

Rob Parker

Hi John,

To accomplish this, you need some code in the form which is opening, to (1)
get the value from the calling form's combobox, then (2) use that value to
filter the form which is opened.

In the Open event of the form which is being opened (frmPackaging), set the
value of cbMainSelect as the value of the combobox:

Me.cbqrytypes =
Forms("KEYSTONEeditids").Controls("cbMainSelect").Column(2)

then apply that via the existing code for the combobox's AfterUpdate event
(I'm assuming that you have code there to filter the form's records in some
fashion):

Me.cbqrytypes_AfterUpdate

Depending on exactly what your code in cbqrytypes does, you may find that
this won't work in the form's Open event, because at that time there are no
records loaded. If it doesn't work there, put it in the form's Load event
and it should be OK.

Note that this requires that the calling form ("KEYSTONEeditids") is still
open (it may be hidden) when frmPackaging opens. From the code you posted
earlier, that seems to be the case. If it's not, then put the value from
cbMainSelect.Column(2) into the OpenArgs parameter when you open
frmPackaging and retrieve it from there when frmPackaging opens.

HTH,

Rob

I'm afraid I don't really understand exactly what you're trying to
do. Or perhaps, you're not understanding Access well enough to
describe your problem.

It's both. And your not understanding is due to my ignorance :)
You say "I'm trying to open a form with its control [cbqrytypes]
filtered ..." which rather confuses me. The DoCmd.OpenForm
statement, when supplied with a Where parameter (in this case, your
strCriteria), will open the specified form (in this case, the form
given by strFormToOpen) with its RecordSource filtered by
strCriteria.

This is something I've obviously never wrapped my brain around. Yes,
in this case the form given by strFormToOpen is what I'm trying to
open WITH its control [cbqrytypes] filtered to the value in [Forms!
[KEYSTONEeditids].Form![cbMainSelect].Column(2)
I don't understand what you mean by "... its control [cbqrytypes]
...". Are you meaning that the value of [cbqrytypes] (whatever
[cbqrytypes] is - this syntax generally refers to a field name) is
the RecordSource for your form which is opening?
No.

Or does [cbqrytypes] contain the name of a control on the
form you are opening - a combobox, perhaps - and are you trying to
set its RecordSource to something filtered by the selection in the
unbound cbMainSelect control on your current form when you open the
form?

We're getting closer! [cbqrytypes] IS the control (a combobox) on the
form that I'm opening. It also serves as a filter for the form. Here's
the form's record source:

SELECT tblProfiles.*, tblProfiles.Type AS PKType
FROM tblProfiles
WHERE (((tblProfiles.Type)=[Forms]![frmPackaging].[Form]!
[cbqryTypes])) OR ((([Forms]![frmPackaging].[Form]![cbqryTypes]) Is
Null));

So...[frmPackaging]is opened from the "Main Menu" [KEYSTONEeditids]
via its control [cbMainSelect]. With the [frmPackaging] opened to the
filtered value AND upon editing the desired record - a user will want
to clear [cbqrytypes] OR make another selection to filter for another
group of entities.

Scenario: from the Main Menu a user selects "Cups" from
[cbMainSelect]. The "Cups" record has a "CP" value in the 2nd column
of [cbMainSelect] and a "PK" value in the 1st column of
[cbMainSelect]. So I'm trying to get [frmPackaging] to open and filter
to the "CP" value. After editing the desired Cup record(s) the user
wants to navigate to the "Glass Bottles" group so rather than closing
the form and going back to the Main Menu they simply select "BTGL"
from [cbqryTypes].

This may seem a bit nuts. I suppose the question would be: Why not
just have [cbMainSelect] list "Packaging" as a value to open
[frmPackaging] and then filter to whatever group a user wants? That
crossed my mind however, it's so much more user-friendly to list all
of the groups in [cbMainSelect] so that a user can open [frmPackaging]
to their desired group without having to think or remember to filter
it once they've opened it.

This is all on the heels of a major re-design. I'm now using a single
form for ALL packaging types. Previously I used ONE form for EACH
type. Whittling things down to one form is an enormous improvement
however it's created this challenge here. Here's more info on the re-
design:

http://groups.google.com/group/micr...1f8aead07?lnk=gst&q=johnlute#49365471f8aead07
Clarification needed before I can assist further,

I hope that helps! Sorry for the length. I couldn't find an easier way
to describe. As I've spelled it out it's become somewhat apparent that
I've got the wrong approach. I'm not sure however because I;m not real
clear on the trick of opening forms per a criteria.

Thanks for your help!
 
J

johnlute

Thanks, Rob.

I actually experimented with that in several ways however the problem
is that the form is subject to being opened via other forms.

Hi John,

To accomplish this, you need some code in the form which is opening, to (1)
get the value from the calling form's combobox, then (2) use that value to
filter the form which is opened.

In the Open event of the form which is being opened (frmPackaging), set the
value of cbMainSelect as the value of the combobox:

    Me.cbqrytypes =
Forms("KEYSTONEeditids").Controls("cbMainSelect").Column(2)

then apply that via the existing code for the combobox's AfterUpdate event
(I'm assuming that you have code there to filter the form's records in some
fashion):

    Me.cbqrytypes_AfterUpdate

Depending on exactly what your code in cbqrytypes does, you may find that
this won't work in the form's Open event, because at that time there are no
records loaded.  If it doesn't work there, put it in the form's Load event
and it should be OK.

Note that this requires that the calling form ("KEYSTONEeditids") is still
open (it may be hidden) when frmPackaging opens.  From the code you posted
earlier, that seems to be the case.  If it's not, then put the value from
cbMainSelect.Column(2) into the OpenArgs parameter when you open
frmPackaging and retrieve it from there when frmPackaging opens.

HTH,

Rob


It's both. And your not understanding is due to my ignorance :)
You say "I'm trying to open a form with its control [cbqrytypes]
filtered ..." which rather confuses me. The DoCmd.OpenForm
statement, when supplied with a Where parameter (in this case, your
strCriteria), will open the specified form (in this case, the form
given by strFormToOpen) with its RecordSource filtered by
strCriteria.
This is something I've obviously never wrapped my brain around. Yes,
in this case the form given by strFormToOpen is what I'm trying to
open WITH its control [cbqrytypes] filtered to the value in [Forms!
[KEYSTONEeditids].Form![cbMainSelect].Column(2)
I don't understand what you mean by "... its control [cbqrytypes]
...". Are you meaning that the value of [cbqrytypes] (whatever
[cbqrytypes] is - this syntax generally refers to a field name) is
the RecordSource for your form which is opening?
Or does [cbqrytypes] contain the name of a control on the
form you are opening - a combobox, perhaps - and are you trying to
set its RecordSource to something filtered by the selection in the
unbound cbMainSelect control on your current form when you open the
form?
We're getting closer! [cbqrytypes] IS the control (a combobox) on the
form that I'm opening. It also serves as a filter for the form. Here's
the form's record source:
SELECT tblProfiles.*, tblProfiles.Type AS PKType
FROM tblProfiles
WHERE (((tblProfiles.Type)=[Forms]![frmPackaging].[Form]!
[cbqryTypes])) OR ((([Forms]![frmPackaging].[Form]![cbqryTypes]) Is
Null));
So...[frmPackaging]is opened from the "Main Menu" [KEYSTONEeditids]
via its control [cbMainSelect]. With the [frmPackaging] opened to the
filtered value AND upon editing the desired record - a user will want
to clear [cbqrytypes] OR make another selection to filter for another
group of entities.
Scenario: from the Main Menu a user selects "Cups" from
[cbMainSelect]. The "Cups" record has a "CP" value in the 2nd column
of [cbMainSelect] and a "PK" value in the 1st column of
[cbMainSelect]. So I'm trying to get [frmPackaging] to open and filter
to the "CP" value. After editing the desired Cup record(s) the user
wants to navigate to the "Glass Bottles" group so rather than closing
the form and going back to the Main Menu they simply select "BTGL"
from [cbqryTypes].
This may seem a bit nuts. I suppose the question would be: Why not
just have [cbMainSelect] list "Packaging" as a value to open
[frmPackaging] and then filter to whatever group a user wants? That
crossed my mind however, it's so much more user-friendly to list all
of the groups in [cbMainSelect] so that a user can open [frmPackaging]
to their desired group without having to think or remember to filter
it once they've opened it.
This is all on the heels of a major re-design. I'm now using a single
form for ALL packaging types. Previously I used ONE form for EACH
type. Whittling things down to one form is an enormous improvement
however it's created this challenge here. Here's more info on the re-
design:
I hope that helps! Sorry for the length. I couldn't find an easier way
to describe. As I've spelled it out it's become somewhat apparent that
I've got the wrong approach. I'm not sure however because I;m not real
clear on the trick of opening forms per a criteria.
Thanks for your help!- Hide quoted text -

- Show quoted text -
 
R

Rob Parker

A possible solution to that is to pass the form the name of the form it's
being opened from in the OpenArgs parameter, and then use a Select Case
construct in the Open/Load event to run the appropriate code depending on
the value of OpenArgs

Rob

Thanks, Rob.

I actually experimented with that in several ways however the problem
is that the form is subject to being opened via other forms.

Hi John,

To accomplish this, you need some code in the form which is opening,
to (1) get the value from the calling form's combobox, then (2) use
that value to filter the form which is opened.

In the Open event of the form which is being opened (frmPackaging),
set the value of cbMainSelect as the value of the combobox:

Me.cbqrytypes =
Forms("KEYSTONEeditids").Controls("cbMainSelect").Column(2)

then apply that via the existing code for the combobox's AfterUpdate
event (I'm assuming that you have code there to filter the form's
records in some fashion):

Me.cbqrytypes_AfterUpdate

Depending on exactly what your code in cbqrytypes does, you may find
that this won't work in the form's Open event, because at that time
there are no records loaded. If it doesn't work there, put it in the
form's Load event and it should be OK.

Note that this requires that the calling form ("KEYSTONEeditids") is
still open (it may be hidden) when frmPackaging opens. From the code
you posted earlier, that seems to be the case. If it's not, then put
the value from cbMainSelect.Column(2) into the OpenArgs parameter
when you open frmPackaging and retrieve it from there when
frmPackaging opens.

HTH,

Rob


I'm afraid I don't really understand exactly what you're trying to
do. Or perhaps, you're not understanding Access well enough to
describe your problem.
It's both. And your not understanding is due to my ignorance :)
You say "I'm trying to open a form with its control [cbqrytypes]
filtered ..." which rather confuses me. The DoCmd.OpenForm
statement, when supplied with a Where parameter (in this case, your
strCriteria), will open the specified form (in this case, the form
given by strFormToOpen) with its RecordSource filtered by
strCriteria.
This is something I've obviously never wrapped my brain around. Yes,
in this case the form given by strFormToOpen is what I'm trying to
open WITH its control [cbqrytypes] filtered to the value in [Forms!
[KEYSTONEeditids].Form![cbMainSelect].Column(2)
I don't understand what you mean by "... its control [cbqrytypes]
...". Are you meaning that the value of [cbqrytypes] (whatever
[cbqrytypes] is - this syntax generally refers to a field name) is
the RecordSource for your form which is opening?

Or does [cbqrytypes] contain the name of a control on the
form you are opening - a combobox, perhaps - and are you trying to
set its RecordSource to something filtered by the selection in the
unbound cbMainSelect control on your current form when you open the
form?
We're getting closer! [cbqrytypes] IS the control (a combobox) on
the form that I'm opening. It also serves as a filter for the form.
Here's the form's record source:
SELECT tblProfiles.*, tblProfiles.Type AS PKType
FROM tblProfiles
WHERE (((tblProfiles.Type)=[Forms]![frmPackaging].[Form]!
[cbqryTypes])) OR ((([Forms]![frmPackaging].[Form]![cbqryTypes]) Is
Null));
So...[frmPackaging]is opened from the "Main Menu" [KEYSTONEeditids]
via its control [cbMainSelect]. With the [frmPackaging] opened to
the filtered value AND upon editing the desired record - a user
will want to clear [cbqrytypes] OR make another selection to filter
for another group of entities.
Scenario: from the Main Menu a user selects "Cups" from
[cbMainSelect]. The "Cups" record has a "CP" value in the 2nd column
of [cbMainSelect] and a "PK" value in the 1st column of
[cbMainSelect]. So I'm trying to get [frmPackaging] to open and
filter to the "CP" value. After editing the desired Cup record(s)
the user wants to navigate to the "Glass Bottles" group so rather
than closing the form and going back to the Main Menu they simply
select "BTGL" from [cbqryTypes].
This may seem a bit nuts. I suppose the question would be: Why not
just have [cbMainSelect] list "Packaging" as a value to open
[frmPackaging] and then filter to whatever group a user wants? That
crossed my mind however, it's so much more user-friendly to list all
of the groups in [cbMainSelect] so that a user can open
[frmPackaging] to their desired group without having to think or
remember to filter it once they've opened it.
This is all on the heels of a major re-design. I'm now using a
single form for ALL packaging types. Previously I used ONE form for
EACH type. Whittling things down to one form is an enormous
improvement however it's created this challenge here. Here's more
info on the re- design:

Clarification needed before I can assist further,
I hope that helps! Sorry for the length. I couldn't find an easier
way to describe. As I've spelled it out it's become somewhat
apparent that I've got the wrong approach. I'm not sure however
because I;m not real clear on the trick of opening forms per a
criteria.
Thanks for your help!- Hide quoted text -

- Show quoted text -
 
J

johnlute

Hi, Rob.

Thanks for all of the ideas. I finally resolved it! Dumb luck and
persistence. I tried bypassing strFormToOpen IF Column(1) is a "PK"
and hard-coded the form name and added a Requery. The requery was the
trick.

I also needed to change all entities that were of the "PK" class but
NOT packaging. No biggie there. I found other classes that were
actually more appropriate.

Thanks again for all you help!

Private Sub cbMainSelect_AfterUpdate()
Dim strFormToOpen As String
With Me!cbMainSelect
'If no selection has been made, we can't do anything useful.
If IsNull(.Value) Then
Exit Sub
End If

'Here a selection has been made, so open the appropriate form
'for the selection.

'Lookup the form, returning a null string if none is
specified.
strFormToOpen = vbNullString & _
DLookup("FormToOpen", "tblProfileTypes", _
"txtProfileType=""" & .Column(2) & """")
If Me.cbMainSelect.Column(1) = "PK" Then
DoCmd.OpenForm "frmPackaging", acNormal
Forms![frmPackaging].Form![cbqrytypes] = Forms!
[KEYSTONEeditids].Form![cbMainSelect].Column(2)
Forms![frmPackaging].Requery
End If
DoCmd.OpenForm strFormToOpen, acNormal

End With

End Sub



A possible solution to that is to pass the form the name of the form it's
being opened from in the OpenArgs parameter, and then use a Select Case
construct in the Open/Load event to run the appropriate code depending on
the value of OpenArgs

Rob


Thanks, Rob.
I actually experimented with that in several ways however the problem
is that the form is subject to being opened via other forms.
Hi John,
To accomplish this, you need some code in the form which is opening,
to (1) get the value from the calling form's combobox, then (2) use
that value to filter the form which is opened.
In the Open event of the form which is being opened (frmPackaging),
set the value of cbMainSelect as the value of the combobox:
Me.cbqrytypes =
Forms("KEYSTONEeditids").Controls("cbMainSelect").Column(2)
then apply that via the existing code for the combobox's AfterUpdate
event (I'm assuming that you have code there to filter the form's
records in some fashion):
Me.cbqrytypes_AfterUpdate
Depending on exactly what your code in cbqrytypes does, you may find
that this won't work in the form's Open event, because at that time
there are no records loaded. If it doesn't work there, put it in the
form's Load event and it should be OK.
Note that this requires that the calling form ("KEYSTONEeditids") is
still open (it may be hidden) when frmPackaging opens. From the code
you posted earlier, that seems to be the case. If it's not, then put
the value from cbMainSelect.Column(2) into the OpenArgs parameter
when you open frmPackaging and retrieve it from there when
frmPackaging opens.
HTH,
Rob
johnlute wrote:
I'm afraid I don't really understand exactly what you're trying to
do. Or perhaps, you're not understanding Access well enough to
describe your problem.
It's both. And your not understanding is due to my ignorance :)
You say "I'm trying to open a form with its control [cbqrytypes]
filtered ..." which rather confuses me. The DoCmd.OpenForm
statement, when supplied with a Where parameter (in this case, your
strCriteria), will open the specified form (in this case, the form
given by strFormToOpen) with its RecordSource filtered by
strCriteria.
This is something I've obviously never wrapped my brain around. Yes,
in this case the form given by strFormToOpen is what I'm trying to
open WITH its control [cbqrytypes] filtered to the value in [Forms!
[KEYSTONEeditids].Form![cbMainSelect].Column(2)
I don't understand what you mean by "... its control [cbqrytypes]
...". Are you meaning that the value of [cbqrytypes] (whatever
[cbqrytypes] is - this syntax generally refers to a field name) is
the RecordSource for your form which is opening?
No.
Or does [cbqrytypes] contain the name of a control on the
form you are opening - a combobox, perhaps - and are you trying to
set its RecordSource to something filtered by the selection in the
unbound cbMainSelect control on your current form when you open the
form?
We're getting closer! [cbqrytypes] IS the control (a combobox) on
the form that I'm opening. It also serves as a filter for the form.
Here's the form's record source:
SELECT tblProfiles.*, tblProfiles.Type AS PKType
FROM tblProfiles
WHERE (((tblProfiles.Type)=[Forms]![frmPackaging].[Form]!
[cbqryTypes])) OR ((([Forms]![frmPackaging].[Form]![cbqryTypes]) Is
Null));
So...[frmPackaging]is opened from the "Main Menu" [KEYSTONEeditids]
via its control [cbMainSelect]. With the [frmPackaging] opened to
the filtered value AND upon editing the desired record - a user
will want to clear [cbqrytypes] OR make another selection to filter
for another group of entities.
Scenario: from the Main Menu a user selects "Cups" from
[cbMainSelect]. The "Cups" record has a "CP" value in the 2nd column
of [cbMainSelect] and a "PK" value in the 1st column of
[cbMainSelect]. So I'm trying to get [frmPackaging] to open and
filter to the "CP" value. After editing the desired Cup record(s)
the user wants to navigate to the "Glass Bottles" group so rather
than closing the form and going back to the Main Menu they simply
select "BTGL" from [cbqryTypes].
This may seem a bit nuts. I suppose the question would be: Why not
just have [cbMainSelect] list "Packaging" as a value to open
[frmPackaging] and then filter to whatever group a user wants? That
crossed my mind however, it's so much more user-friendly to list all
of the groups in [cbMainSelect] so that a user can open
[frmPackaging] to their desired group without having to think or
remember to filter it once they've opened it.
This is all on the heels of a major re-design. I'm now using a
single form for ALL packaging types. Previously I used ONE form for
EACH type. Whittling things down to one form is an enormous
improvement however it's created this challenge here. Here's more
info on the re- design:
http://groups.google.com/group/microsoft.public.access.formscoding/br....
Clarification needed before I can assist further,
I hope that helps! Sorry for the length. I couldn't find an easier
way to describe. As I've spelled it out it's become somewhat
apparent that I've got the wrong approach. I'm not sure however
because I;m not real clear on the trick of opening forms per a
criteria.
Thanks for your help!- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 

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

Similar Threads

filtering a form 7
remove a filter 5
Error 3075 Syntax Error 5
Problem with date format 1
Multiple Criteria in Code 13
List box question -- code 5
Why has this stopped working 5
Two multi-select listboxes 5

Top