Open a Form defined by combo

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

Guest

Hi all,

I got a [Combo709] on my [Main] form with some values ("A", "B", "C", etc.)
which i want to use to open different forms. The forms names are: "F_A",
"F_B", "F_C", etc.

I was trying to make a button for this, but when I click it, I get a message
"The action or method requires a Form Name argument".

I am not really good at writing codes - can somebody show me what is wrong
here?

Here is the code for my button:

Private Sub Command707_Click()
On Error GoTo Err_Command707_Click

Dim stDocName As String
Dim stLinkCriteria As String

If Me.Combo709 = "A" Then
stDocName = "F_A"
ElseIf Me.Combo709 = "B" Then
stDocName = "F_B"

End If
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command707_Click:
Exit Sub

Err_Command707_Click:
MsgBox Err.Description
Resume Exit_Command707_Click

End Sub

Your help will be very much appreciated.
Lana
 
If the value selected for Combo709 is neither "A" nor "B," then the DoCmd is
executed without any form name being assigned to stDocName, which results in
the error message you are receiving. The value of Combo709 is taken from the
bound column, not the displayed value column. Perhaps the following would
help:

Private Sub Command707_Click()
On Error GoTo Err_Command707_Click

Dim stDocName As String

stDocName = "F_" & Me!Combo709.Column(1)
DoCmd.OpenForm stDocName

Exit_Command707_Click:
Exit Sub

Err_Command707_Click:
MsgBox Err.Description
Resume Exit_Command707_Click

End Sub

.. . . where Combo709 is the name of the combo box (but I'd recommend
changing this to a more descriptive name, as well as your button's name) and
Column(1) is the second column of the combo box, which is the value being
displayed.

Or, if you'd like to keep the If-ElseIf block, then try:

If Me!Combo709.Column(1) = "A" Then
stDocName = "F_A"
ElseIf Me!Combo709.Column(1) = "B" Then
stDocName = "F_B"
End If


HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Lana said:
I got a [Combo709] on my [Main] form with some values ("A", "B", "C", etc.)
which i want to use to open different forms. The forms names are: "F_A",
"F_B", "F_C", etc.

I was trying to make a button for this, but when I click it, I get a message
"The action or method requires a Form Name argument".

I am not really good at writing codes - can somebody show me what is wrong
here?

Here is the code for my button:

Private Sub Command707_Click()
On Error GoTo Err_Command707_Click

Dim stDocName As String
Dim stLinkCriteria As String

If Me.Combo709 = "A" Then
stDocName = "F_A"
ElseIf Me.Combo709 = "B" Then
stDocName = "F_B"

End If
DoCmd.OpenForm stDocName, , , stLinkCriteria
[snip]


From your description, I would expect that to work if the
combo box's value is either an "A" or a "B". Are you sure
that the combo box's Value is what you think it is? What is
the combo box's Bound column and what setting so you have
for the ColumnWidths property.

You can probably shorten this dramatically by using this
code instead:

Private Sub Command707_Click()
On Error GoTo Err_Command707_Click

Dim stDocName As String

stDocName = "F_" & Me.Combo709
DoCmd.OpenForm stDocName
. . .

However, I have a serious suspicion that this entire
scenario has gone astray somewhere earlier. It just doesn't
seem right to need different forms for whatever reason it is
you are making the combo box selection.
 
I was thinking about using the same form for displaying the results, but my
task is a bit complicated and i am not sure if it is possible to do so.

Let me explain the situation - may be you can give me some advise:

I have a table with fields "A", "B", "C", etc. (12 fields).
My [Main] form is for search. It has a combo with a rowsource from other
small table with only 12 records which contain the names of the 12 fields of
the other table ("A", "B", "C", etc.)
Depending on what was value chosen in this combo-box, I want to perform
search in one of the 12 fields of the big table and return results in another
form.

The reason why I was using 12 forms instead of 1 is that I dont know how to
alter the control source of the text-box so that it would display the records
of different fields depending on the value chosen from combobox. (And it must
change the formatting of the text-box as well - like using different Fonts
for some of the 12 fields)

Each of my 12 forms are based on 12 queries (so the query would run on
opening the form).

They are actually selection queries very similar to each other. I would love
to use one query instead of 12, but dont know how. :(
They have a condition like:
Querry A:
WHERE ((([BigTable]![A]) Like ("*"+[Find]+"*")));
Querry B:
WHERE ((([BigTable]!) Like ("*"+[Find]+"*")));

I guess you could use one query for all of them, but I dont know how to
introduce the dependance to the combobox value in here neither.

All this code writing thing seems so complicated to me. I feel that there
should be a good solution for all that, but dont have a slightest idea how to
do that.

Would be very greatful if somebody could help.

Thank you.
Lana


Marshall Barton said:
Lana said:
I got a [Combo709] on my [Main] form with some values ("A", "B", "C", etc.)
which i want to use to open different forms. The forms names are: "F_A",
"F_B", "F_C", etc.

I was trying to make a button for this, but when I click it, I get a message
"The action or method requires a Form Name argument".

I am not really good at writing codes - can somebody show me what is wrong
here?

Here is the code for my button:

Private Sub Command707_Click()
On Error GoTo Err_Command707_Click

Dim stDocName As String
Dim stLinkCriteria As String

If Me.Combo709 = "A" Then
stDocName = "F_A"
ElseIf Me.Combo709 = "B" Then
stDocName = "F_B"

End If
DoCmd.OpenForm stDocName, , , stLinkCriteria
[snip]


From your description, I would expect that to work if the
combo box's value is either an "A" or a "B". Are you sure
that the combo box's Value is what you think it is? What is
the combo box's Bound column and what setting so you have
for the ColumnWidths property.

You can probably shorten this dramatically by using this
code instead:

Private Sub Command707_Click()
On Error GoTo Err_Command707_Click

Dim stDocName As String

stDocName = "F_" & Me.Combo709
DoCmd.OpenForm stDocName
. . .

However, I have a serious suspicion that this entire
scenario has gone astray somewhere earlier. It just doesn't
seem right to need different forms for whatever reason it is
you are making the combo box selection.
 
Thank you Camaro, you were right about the bound columns.
When i added ".Column(1)" to my code - it all worked fine.

and then i changed the code as you suggested (to simplify it) - and it also
worked!!!

Thank you so much for a good advice!
Lana


'69 Camaro said:
If the value selected for Combo709 is neither "A" nor "B," then the DoCmd is
executed without any form name being assigned to stDocName, which results in
the error message you are receiving. The value of Combo709 is taken from the
bound column, not the displayed value column. Perhaps the following would
help:

Private Sub Command707_Click()
On Error GoTo Err_Command707_Click

Dim stDocName As String

stDocName = "F_" & Me!Combo709.Column(1)
DoCmd.OpenForm stDocName

Exit_Command707_Click:
Exit Sub

Err_Command707_Click:
MsgBox Err.Description
Resume Exit_Command707_Click

End Sub

. . . where Combo709 is the name of the combo box (but I'd recommend
changing this to a more descriptive name, as well as your button's name) and
Column(1) is the second column of the combo box, which is the value being
displayed.

Or, if you'd like to keep the If-ElseIf block, then try:

If Me!Combo709.Column(1) = "A" Then
stDocName = "F_A"
ElseIf Me!Combo709.Column(1) = "B" Then
stDocName = "F_B"
End If


HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.


Lana said:
Hi all,

I got a [Combo709] on my [Main] form with some values ("A", "B", "C", etc.)
which i want to use to open different forms. The forms names are: "F_A",
"F_B", "F_C", etc.

I was trying to make a button for this, but when I click it, I get a message
"The action or method requires a Form Name argument".

I am not really good at writing codes - can somebody show me what is wrong
here?

Here is the code for my button:

Private Sub Command707_Click()
On Error GoTo Err_Command707_Click

Dim stDocName As String
Dim stLinkCriteria As String

If Me.Combo709 = "A" Then
stDocName = "F_A"
ElseIf Me.Combo709 = "B" Then
stDocName = "F_B"

End If
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command707_Click:
Exit Sub

Err_Command707_Click:
MsgBox Err.Description
Resume Exit_Command707_Click

End Sub

Your help will be very much appreciated.
Lana
 
You're welcome! Glad it helped.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.


Lana said:
Thank you Camaro, you were right about the bound columns.
When i added ".Column(1)" to my code - it all worked fine.

and then i changed the code as you suggested (to simplify it) - and it
also
worked!!!

Thank you so much for a good advice!
Lana


'69 Camaro said:
If the value selected for Combo709 is neither "A" nor "B," then the DoCmd
is
executed without any form name being assigned to stDocName, which results
in
the error message you are receiving. The value of Combo709 is taken from
the
bound column, not the displayed value column. Perhaps the following
would
help:

Private Sub Command707_Click()
On Error GoTo Err_Command707_Click

Dim stDocName As String

stDocName = "F_" & Me!Combo709.Column(1)
DoCmd.OpenForm stDocName

Exit_Command707_Click:
Exit Sub

Err_Command707_Click:
MsgBox Err.Description
Resume Exit_Command707_Click

End Sub

. . . where Combo709 is the name of the combo box (but I'd recommend
changing this to a more descriptive name, as well as your button's name)
and
Column(1) is the second column of the combo box, which is the value being
displayed.

Or, if you'd like to keep the If-ElseIf block, then try:

If Me!Combo709.Column(1) = "A" Then
stDocName = "F_A"
ElseIf Me!Combo709.Column(1) = "B" Then
stDocName = "F_B"
End If


HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message
will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the
question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember
that
questions answered the quickest are often from those who have a history
of
rewarding the contributors who have taken the time to answer questions
correctly.


Lana said:
Hi all,

I got a [Combo709] on my [Main] form with some values ("A", "B", "C",
etc.)
which i want to use to open different forms. The forms names are:
"F_A",
"F_B", "F_C", etc.

I was trying to make a button for this, but when I click it, I get a
message
"The action or method requires a Form Name argument".

I am not really good at writing codes - can somebody show me what is
wrong
here?

Here is the code for my button:

Private Sub Command707_Click()
On Error GoTo Err_Command707_Click

Dim stDocName As String
Dim stLinkCriteria As String

If Me.Combo709 = "A" Then
stDocName = "F_A"
ElseIf Me.Combo709 = "B" Then
stDocName = "F_B"

End If
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command707_Click:
Exit Sub

Err_Command707_Click:
MsgBox Err.Description
Resume Exit_Command707_Click

End Sub

Your help will be very much appreciated.
Lana
 
Lana said:
I was thinking about using the same form for displaying the results, but my
task is a bit complicated and i am not sure if it is possible to do so.

Let me explain the situation - may be you can give me some advise:

I have a table with fields "A", "B", "C", etc. (12 fields).
My [Main] form is for search. It has a combo with a rowsource from other
small table with only 12 records which contain the names of the 12 fields of
the other table ("A", "B", "C", etc.)
Depending on what was value chosen in this combo-box, I want to perform
search in one of the 12 fields of the big table and return results in another
form.

The reason why I was using 12 forms instead of 1 is that I dont know how to
alter the control source of the text-box so that it would display the records
of different fields depending on the value chosen from combobox. (And it must
change the formatting of the text-box as well - like using different Fonts
for some of the 12 fields)

Each of my 12 forms are based on 12 queries (so the query would run on
opening the form).

They are actually selection queries very similar to each other. I would love
to use one query instead of 12, but dont know how. :(
They have a condition like:
Querry A:
WHERE ((([BigTable]![A]) Like ("*"+[Find]+"*")));
Querry B:
WHERE ((([BigTable]!) Like ("*"+[Find]+"*")));

I guess you could use one query for all of them, but I dont know how to
introduce the dependance to the combobox value in here neither.

All this code writing thing seems so complicated to me. I feel that there
should be a good solution for all that, but dont have a slightest idea how to
do that.

Lana said:
I got a [Combo709] on my [Main] form with some values ("A", "B", "C", etc.)
which i want to use to open different forms. The forms names are: "F_A",
"F_B", "F_C", etc.

I was trying to make a button for this, but when I click it, I get a message
"The action or method requires a Form Name argument".

I am not really good at writing codes - can somebody show me what is wrong
here?

Here is the code for my button:

Private Sub Command707_Click()
On Error GoTo Err_Command707_Click

Dim stDocName As String
Dim stLinkCriteria As String

If Me.Combo709 = "A" Then
stDocName = "F_A"
ElseIf Me.Combo709 = "B" Then
stDocName = "F_B"

End If
DoCmd.OpenForm stDocName, , , stLinkCriteria
[snip]
Marshall Barton said:
From your description, I would expect that to work if the
combo box's value is either an "A" or a "B". Are you sure
that the combo box's Value is what you think it is? What is
the combo box's Bound column and what setting so you have
for the ColumnWidths property.

You can probably shorten this dramatically by using this
code instead:

Private Sub Command707_Click()
On Error GoTo Err_Command707_Click

Dim stDocName As String

stDocName = "F_" & Me.Combo709
DoCmd.OpenForm stDocName
. . .

However, I have a serious suspicion that this entire
scenario has gone astray somewhere earlier. It just doesn't
seem right to need different forms for whatever reason it is
you are making the combo box selection.
 
Lana said:
I was thinking about using the same form for displaying the results, but my
task is a bit complicated and i am not sure if it is possible to do so.

Let me explain the situation - may be you can give me some advise:

I have a table with fields "A", "B", "C", etc. (12 fields).
My [Main] form is for search. It has a combo with a rowsource from other
small table with only 12 records which contain the names of the 12 fields of
the other table ("A", "B", "C", etc.)
Depending on what was value chosen in this combo-box, I want to perform
search in one of the 12 fields of the big table and return results in another
form.

The reason why I was using 12 forms instead of 1 is that I dont know how to
alter the control source of the text-box so that it would display the records
of different fields depending on the value chosen from combobox. (And it must
change the formatting of the text-box as well - like using different Fonts
for some of the 12 fields)

Each of my 12 forms are based on 12 queries (so the query would run on
opening the form).

They are actually selection queries very similar to each other. I would love
to use one query instead of 12, but dont know how. :(
They have a condition like:
Querry A:
WHERE ((([BigTable]![A]) Like ("*"+[Find]+"*")));
Querry B:
WHERE ((([BigTable]!) Like ("*"+[Find]+"*")));

I guess you could use one query for all of them, but I dont know how to
introduce the dependance to the combobox value in here neither.

All this code writing thing seems so complicated to me. I feel that there
should be a good solution for all that, but dont have a slightest idea how to
do that.



Sorry about the empty reply, hit the wrong key.

I'm pretty sure there's a way to use a single query and one
form to do all this. First I must make an assumption that
the data form is not open when the search form is used. If
this is not a valid assumption, let me know before we go too
far down this path.

If you use a single query (without any criteria) that
retrieves **all** the relevant data fields, the data can be
filtered by using the OpenForm method's WhereCondition
argument:

Dim strCriteria As String
strCriteria = Me.Combo709 & " Like '*" & [Find] & "*' "
DoCmd OpenForm "the form", _
WhereCondition:= strCriteria, _
OpenArgs:= Me.Combo709

I used the OpenArgs argument to pass the name of the field
to the form so the form can adapt itself to the field it is
supposed to display.

The Form's Open event procedure can then examine OpenArgs
and make the appropriate adjustments. Here's a vague idea
of some of the things you might want to do to "customize"
the form depending on the selected field:

Select Case Me.OpenArgs
Case "A"
With Me.sometextbox
.ControlSource = Me.OpenArgs
.FontName = "Arial"
.FontSize = 12
. . .
End With
Case "B"
. . .
. . .
End Select
 
Back
Top