Parameter in VBA

laurenh5516

New Member
Joined
Nov 20, 2017
Messages
9
I am trying to code parameters in excel VBA from an access query that has 2 date parameters. I have parameters in my code, but I still get an error code that says 2 parameters are expected.


Sub UpdateForecast()
Application.ScreenUpdating = False
'On Error Resume Next

Dim MyDatabase As DAO.Database
Dim QueryDef As DAO.QueryDef

Dim i As Integer

Set MyDatabase = DBEngine.OpenDatabase _
("C:\Users" & Environ("UserName") & "\Turnaround Tracking\Construction Hiring Plan.accdb")
Set QueryDef = MyDatabase.QueryDefs("qry_WeekendForecastOfficial")

Set MyQuery = QueryDef.OpenRecordset

QueryDef.Parameters(0) = InputBox("Select Start Date")
QueryDef.Parameters(0) = InputBox("Select Finish Date")
 
Last edited:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Code:
QueryDef.Parameters([COLOR="#FF0000"]0[/COLOR]) = InputBox("Select Start Date")
QueryDef.Parameters([COLOR="#FF0000"]0[/COLOR]) = InputBox("Select Finish Date")
Shouldn't those be different?
 
Upvote 0

Forum statistics

Threads
1,216,591
Messages
6,131,622
Members
449,658
Latest member
JasonEncon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top