Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Enter Parameter once for multiple parameter queries

Status
Not open for further replies.

noel0589

Electrical
Sep 23, 2004
50
Hi all, I created a command which runs an update query and an append query. Each query requires that the user enter an input. The input is the same for each query, but because it is two different queries, access prompts to enter the same number twice. Could someone show how to code so that i only have to enter once?

Private sub command29_click()

docmd.runsql "update table set field = [ENTER] where isnull(field)"

docmd.runsql "update table1 set field1=[ ]![ ]![ ]
where (([table1].[field2]=[ENTER]))

end sub

I am new so please help. In this case I want to make it so that [Enter] only has to be entered once.
Is there a way to prompt for a variable before running the SQL and then setting [Enter] to be equal to that variable!?!?!
Thanks for any response!!
 
Replies continue below

Recommended for you

Hi Noel,

Get the input parameter from the user with your VB code, and then use this value in the query strings. Like the following.
Code:
Private Sub Command0_click()

Dim strInput As String

strInput = InputBox("Please enter parameter")
DoCmd.RunSQL "update Transactions set Amount = " & strInput & _
             " where isnull(Amount)"
DoCmd.RunSQL "update Receipts set Checked = True" & _
             " where Receipts.Amount = " & strInput

End Sub
Hope this helps. Cheers.

Yeasir Rahul

Principal, VoltSmith Technologies
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor