Open a form from a command button

J

JDP

I am trying to open a form from a command button.
This works fine.

Private Sub Go_To_Healthcare_Invoice_Click()
On Error GoTo Err_Go_To_Healthcare_Invoice_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim Service_Code As String

stDocName = "Healthcare Invoice Number Form and supp"
stLinkCriteria = "[Invoice_No]=" & "'" & Me!
[Invoice] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

....

I am trying to oepn one of several forms based upon the
value set for Service_Code. When I modify the code, he
button does not work. I want to get the code working for
the default condition before adding ELSEIF statements.



If "[Service_Code]" = "Consol" Then
stDocName = "Healthcare Invoice Number Form and
supp"
stLinkCriteria = "[Invoice_No]=" & "'" & Me!
[Invoice] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

Thank you in advance, and any help would be appreciated.
 
J

Jeff Boyce

Are you saying that if the form you are on has a value of "Consol" in a
control named [Service_Code], you want to modify stDocName & stLinkCriteria?

If Me![Service_Code] = "Consol" Then ...

By the way, you may want to use a control name that differs from the name of
the field (I assume the fieldname is [Service_Code]). Maybe you could
rename the control on the form to something like:

txtServiceCode

so you (and Access) can tell whether you are referring to the control on the
form, or the underlying field in the table.
 
V

Van T. Dinh

The probelm is in the If statement:

If "[Service_Code]" = "Consol" Then

The LHS and RHS of the equal operator will be interpreted as literal Strings
and they are always different.

If you mean the current value of the Control [Service_Code] on your Form,
you should use:

If Me.[Service_Code] = "Consol" Then
 

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