Opening the second from if the value is ...

G

Guest

Hi
On my first form I have a drop-down box and I want if user selects specific
value, access opens my second from, I tried following code but not working:

DoCmd.OpenForm "prc frm", , , , , , Reason_for_visit = [Procedure]
my second from field on first form specific
value
 
G

Guest

The code should go in the After Update event of the combo box (dropdown) and
I am suprised you did not get an error. The syntax is not correct. Try it
this way:

If Me.SomeCombo = "The value you want to run the form" Then
DoCmd.OpenForm "prc frm", , , , , , Reason_for_visit = [Procedure]
The part that is the problem I can't tell what to do to fix it. The correct
syntax is
"[RecordSetField] = '" & ValueToSearchFor & "'"

[RecordSetField] has to be a field in the record source of the form you are
opening.
ValueToSearchFor has to be a value that you would expect to find in
[RecordSetField] in at least one record in the form's record source.
In this case, I am guessing this is a text value. That is the reason for
the qoutes.
If the data type of [RecordSetField] is text, then ValueToSearchFor has to
be enclosed in either single or double qoutes.
 
G

Guest

VB code you wrote is not working either.
Let me explain
the name of the field is "Reason of visit" and the value I wish to open the
next form is " Procedure"
I wrote:
If Me.Reason_for-visitCombo = "Procedure" Then
DoCmd.OpenForm "prc frm"

Klatuu said:
The code should go in the After Update event of the combo box (dropdown) and
I am suprised you did not get an error. The syntax is not correct. Try it
this way:

If Me.SomeCombo = "The value you want to run the form" Then
DoCmd.OpenForm "prc frm", , , , , , Reason_for_visit = [Procedure]
The part that is the problem I can't tell what to do to fix it. The correct
syntax is
"[RecordSetField] = '" & ValueToSearchFor & "'"

[RecordSetField] has to be a field in the record source of the form you are
opening.
ValueToSearchFor has to be a value that you would expect to find in
[RecordSetField] in at least one record in the form's record source.
In this case, I am guessing this is a text value. That is the reason for
the qoutes.
If the data type of [RecordSetField] is text, then ValueToSearchFor has to
be enclosed in either single or double qoutes.
Ramtin said:
Hi
On my first form I have a drop-down box and I want if user selects specific
value, access opens my second from, I tried following code but not working:

DoCmd.OpenForm "prc frm", , , , , , Reason_for_visit = [Procedure]
my second from field on first form specific
value
 
G

Guest

I did not expect it to work. It was an incomplete example because I couldn't
figure out what you are trying to do.

If you have a combo on your form named Reason_for-visitCombo and Procedure
is one of the items in the list and the code is in the After Update event of
the combo, then the code you posted should open the form.

What happens when you select an item in the combo's list?

Ramtin said:
VB code you wrote is not working either.
Let me explain
the name of the field is "Reason of visit" and the value I wish to open the
next form is " Procedure"
I wrote:
If Me.Reason_for-visitCombo = "Procedure" Then
DoCmd.OpenForm "prc frm"

Klatuu said:
The code should go in the After Update event of the combo box (dropdown) and
I am suprised you did not get an error. The syntax is not correct. Try it
this way:

If Me.SomeCombo = "The value you want to run the form" Then
DoCmd.OpenForm "prc frm", , , , , , Reason_for_visit = [Procedure]
The part that is the problem I can't tell what to do to fix it. The correct
syntax is
"[RecordSetField] = '" & ValueToSearchFor & "'"

[RecordSetField] has to be a field in the record source of the form you are
opening.
ValueToSearchFor has to be a value that you would expect to find in
[RecordSetField] in at least one record in the form's record source.
In this case, I am guessing this is a text value. That is the reason for
the qoutes.
If the data type of [RecordSetField] is text, then ValueToSearchFor has to
be enclosed in either single or double qoutes.
Ramtin said:
Hi
On my first form I have a drop-down box and I want if user selects specific
value, access opens my second from, I tried following code but not working:

DoCmd.OpenForm "prc frm", , , , , , Reason_for_visit = [Procedure]
my second from field on first form specific
value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top