Open Form with Parameter?

G

Guest

I have a form (frmSARsByElement) based on a query that asks for a parameter,
"Element".

I am trying to build a main form with a text box (txtElement) and a button
that will open frmSARByElement using what is typed into txtElement as the
parameter.

What I am using is not working, the Parameter "pop up" box still pops up:
Private Sub cmdFindSARsByElement_Click()
Dim stFrmName As String
Dim stLinkCriteria As String

stFrmName = "frmSARsByElement"
stLinkCriteria = "[Element]=" & "'" & Me.txtElement & "'"
DoCmd.OpenForm stFrmName, , , stLinkCriteria
End Sub

I would appreciate any help you can give me.
Thank you, Judy
 
G

Guest

Judy

I think what's happening here is that you are providing the Element field to
the form, but the underlying query doesn't receive the parameter so it asks
the user. If this is the case, you can solve it one of two ways.

1. Check the query for frmSARsByElement and see if the Element field is
looking for a parameter. If so, you should be able to delete this requirement
from the query, since you are providing it when you call OpenForm. The form
will apply the where condition from the entire recordset the query provides.

OR

2. In the Element field for the query, type
=Forms!frmSARsByElement.txtElement in the criteria box. If frmSARsByElement
is a subform, you will need to reference the main form first, and then the
subform control, and finally the subform itself. In your code, change the
second to last line to this:

DoCmd.OpenForm stFrmName

You can also comment out any code that sets up the strCriteria, since you
won't need these lines.


One final note -- if the problem is not what I suggested above, your query
may be looking for additional parameters than the Element field. If this is
the case, make sure that the query can find the data it is looking for, or
else provide it in the OpenForm the same way that you are providing the
Element field.
 
G

Guest

Thank you, Mike. This works. I was hoping there was a way to use the same
query and form that I already had (that prompted the user for the Element
with "Enter Parameter Value" and "Element" rather than
"Forms!frmMain!cboElement").

Thank you for responding!

mike said:
Judy

I think what's happening here is that you are providing the Element field to
the form, but the underlying query doesn't receive the parameter so it asks
the user. If this is the case, you can solve it one of two ways.

1. Check the query for frmSARsByElement and see if the Element field is
looking for a parameter. If so, you should be able to delete this requirement
from the query, since you are providing it when you call OpenForm. The form
will apply the where condition from the entire recordset the query provides.

OR

2. In the Element field for the query, type
=Forms!frmSARsByElement.txtElement in the criteria box. If frmSARsByElement
is a subform, you will need to reference the main form first, and then the
subform control, and finally the subform itself. In your code, change the
second to last line to this:

DoCmd.OpenForm stFrmName

You can also comment out any code that sets up the strCriteria, since you
won't need these lines.


One final note -- if the problem is not what I suggested above, your query
may be looking for additional parameters than the Element field. If this is
the case, make sure that the query can find the data it is looking for, or
else provide it in the OpenForm the same way that you are providing the
Element field.


Judy Ward said:
I have a form (frmSARsByElement) based on a query that asks for a parameter,
"Element".

I am trying to build a main form with a text box (txtElement) and a button
that will open frmSARByElement using what is typed into txtElement as the
parameter.

What I am using is not working, the Parameter "pop up" box still pops up:
Private Sub cmdFindSARsByElement_Click()
Dim stFrmName As String
Dim stLinkCriteria As String

stFrmName = "frmSARsByElement"
stLinkCriteria = "[Element]=" & "'" & Me.txtElement & "'"
DoCmd.OpenForm stFrmName, , , stLinkCriteria
End Sub

I would appreciate any help you can give me.
Thank you, Judy
 

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


Top