Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Entering two values before going into form 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Anyway I can get one form prompt that asks for two data values before it opens my form?

I want it to say "Enter Project ID" for one value and the next line to say "Enter Customer ID".

I can do it with one prompt for each field by using the query criteria "Like[Enter Project ID]" and "Like[Enter Customer ID]" but it gives two different enter prompts before getting to the form.
 
I don't think so. Pretty sure You're stuck with two. Bummer.

-Josh ------------------
-JPeters
Got a helpful tip for Access Users? Check out and contribute to 'How to Keep Your Databases from becoming Overwhelming!'
thread181-293590
jpeters@guidemail.com
------------------
 
Not if you use only a parameter query but there is no reason you can't 'roll your own' by creating the form that asks the questions then, verify they are correct and pass sing it on to the second form where you want to use the answers by using the OpenArgs parameter. Then second form being called would parse the two values from the OpenArgs property and create the SQL or whatever you want to do.

Form1-----------
Dim strVal1 As String
Dim strVal2 As String
Dim strOpenArgs As String

strVal1 = Me.txtVal1
strVal2 = Me.txtVal2
strOpenArgs = strVal1 & ";" & strVal2

DoCmd.OpenForm Formname:"frmMyForm", OpenArgs:=strOpenArgs
'Then close this form

Form2
If Len(Me.OpenArgs) > 0 Then
'Parse the two parts of the OpenArgs stream
'Use the two parts to create SQL
'Assign the SQL to RecordSource
Else
MsgBox "Invalid OpenArgs request"
Cancel = True
End If
----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
 

Where would this go in my form 1? In the "on open" event???
Form1-----------
Dim strVal1 As String
Dim strVal2 As String
Dim strOpenArgs As String

strVal1 = Me.txtVal1
strVal2 = Me.txtVal2
strOpenArgs = strVal1 & ";" & strVal2

DoCmd.OpenForm Formname:"frmMyForm", OpenArgs:=strOpenArgs
'Then close this form
 
scking. Great idea. I didn't think it through, that would work well. I'd probably do it a bit differently than you would tough.

If you don't know much about code, I think you could probably create a form that has 2 unbound text boxes in it (with their appropriate labels), and a button to open up the Form that runs off of your query (the one you're trying to open).

Now in your query, put your criteria as this:
Forms![frmMyForm]![UnboundTextBoxName]

Where FrmMyForm is your form name, and UnboundTextBox name... I guess I don't have to explain everything .. ;-)
Do this in both lookup fields.

Now make your button on the form.

Sub Button_OnClick()
DoCmd.OpenForm "qryMyQuery" 'change to your query name
DoCmd.Close
End Sub

Hope that helps a bit.
scking's way works too. It's pretty slick.

-Josh
------------------
-JPeters
Got a helpful tip for Access Users? Check out and contribute to 'How to Keep Your Databases from becoming Overwhelming!'
thread181-293590
jpeters@guidemail.com
------------------
 
Every developer has a few solutions to the same problem. The fact that they sometimes come up with the same one is either because the question is trivial or they learned from the same source or blind luck.

I recommend Josh's alternative as a little simpler than mine.

You could use the 'WhereCondition' or the 'FilterName' parameters of the DoCmd.OpenForm but it would require putting together the pieces. And there are a number of associated verification problems with an unstructure text field being used as a valid value.

On the Button_OnClick event you COULD enter

Dim varVal1 As String
Dim varVal2 As String
Dim strCriteria As String

On Error GoTo HandleErr

If Me.TextBox1 <> &quot;&quot; Then
varVal1 = Me.TextBox1
Else
MsgBox &quot;Please enter a value for the textbox&quot;
GoTo Exit_Proc
End If

If Me.TextBox2 <> &quot;&quot; Then
varVal2 = Me.TextBox2
Else
MsgBox &quot;Please enter a value for the second textbox&quot;
GoTo Exit_Proc
End If

strCriteria = &quot;ID='&quot; & varVal1 & &quot;' And Name='&quot; & varVal2 & &quot;'&quot;
DoCmd.OpenForm Formname:=&quot;frmYourForm&quot;, WhereCondition:=strCriteria

Exit_Proc:
Exit Sub

HandleErr:
MsgBox Err.Description
Resume Exit_Proc
Resume
End Sub

Remember, this would open the form where the condition was met but NOT filter the data. That would be done with other parameters.

----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top