I have an Excel user form with a couple of controls (combo box, calendar
control) that are designed to pass selected variables as parameters to an
Access query using DAO. It works great with the parameters hard-coded, but
I'm struggling with trying to pass the values in as variables. The last line
of the following code generates a "Subscript out of range" error and the
Help message indicates a couple of possibilities. My guess is that the code
is "referencing a non-existent collection member", which I interpret to mean
the following public variables are not part of the collection.
If that's the case, how do I add the variables to the collection? Or do I
have something else going on, i.e. the Select Case is not the right tool?
Thanks - Any help is appreciated - RobertC
Public strQuery As String
Public strQueryName As String
Public strQueryParameters As String
Public strWorksheet As String
'// Establish variables
Private Sub cboSelectQuery_Change()
strQuery = cboSelectQuery.Text
Select Case strQuery
Case Is = "JC Budgets to Date"
strQueryName = "JC Budgets to Date"
strQueryParameters = "Enter Transaction Date: mm/dd/yy"
strWorksheet = "JC Budgets"
Case Is = "JC Costs to Date"
strQueryName = "JC Costs to Date"
strQueryParameters = "Enter Accounting Date: mm/dd/yy"
strWorksheet = "JC Costs"
Case Is = "JC Detail to Date"
strQueryName = "JC Detail to Date"
strQueryParameters = "Enter Accounting Date: mm/dd/yy"
strWorksheet = "JC Detail"
End Select
Private Sub cmdLoadDate_Click()
Dim Db As Database
Dim Qd As QueryDef
Dim Rs As Recordset
Dim Ws As Object
Dim i As Integer
Dim Path As String
Dim sTransDate As String
Dim nRet As Long
'// evalInput will return success or failure, and if successful,
'// set passed string to the user-selected date and pass-in date
variable.
nRet = EvaluateInput(sTransDate)
'// Unload form and exit if input not valid
If nRet <> 0 Then
'// Err msg displayed in EvaluateInput()
'// Unload the form and exit
Exit Sub
Else
Unload frmSelectVariables
End If
'// Set the Path to the database.
Path = "k:\database\IPP.mdb"
'// Set the Worksheet
Set Ws = Sheets(strWorksheet) = strWorksheet
'// More code here