Link to home
Start Free TrialLog in
Avatar of Aravind Ranganathan
Aravind Ranganathan

asked on

too few parameters error not understanding why??

this is a access application, i have a method that gets all the selected values from a listbox and is delimited by a comma. i than take those values and pass it into a where clause and use the 'IN' operator on it but i am getting the too few parameters error.

my code.

DoCmd.SetWarnings False
SelectedList = GetSelectedItems(Me.WeekSelector)
Query = "INSERT INTO [WorkTable]([L Batch ID], [Pay Group], [Pay Group Description], [General Ledger Account], [General Ledger Cost Center], [General Ledger Department], [Work Center], [Pay Period Ending Date], Hours, Amount, Week, [Pay Type Code], [Pay Type Description], [File Number], Name, [HOURLY SALARY], [FULL TIME_PART TIME], ACTIVE_INACTIVE, [HOURLY RATE], ID)" _
& " SELECT LoadTable.[L Batch ID], LoadTable.[Pay Group], LoadTable.[Pay Group Description], LoadTable.[General Ledger Account], LoadTable.[General Ledger Cost Center], LoadTable.[General Ledger Department], LoadTable.[Work Center], LoadTable.[Pay Period Ending Date], LoadTable.Hours, LoadTable.Amount, LoadTable.Week, LoadTable.[Pay Type Code], LoadTable.[Pay Type Description], LoadTable.[File Number], LoadTable.Name, LoadTable.[HOURLY SALARY], LoadTable.[FULL TIME_PART TIME], LoadTable.ACTIVE_INACTIVE, LoadTable.[HOURLY RATE], LoadTable.ID" _
& " FROM LoadTable " _
& " WHERE (((LoadTable.Week) IN (SelectedList)));"
CurrentDb.Execute (Query)
DoCmd.SetWarnings True

Open in new window




Public Function GetSelectedItems(lBox As Object) As String
'returns an array of selected items in a ListBox
Dim tmpArray() As Variant
Dim i As Integer
Dim selCount As Integer
    selCount = -1
    '## Iterate over each item in the ListBox control:
    For i = 0 To lBox.ListCount - 1
        '## Check to see if this item is selected:
        If lBox.Selected(i) = True Then
            '## If this item is selected, then add it to the array
            selCount = selCount + 1
            ReDim Preserve tmpArray(selCount)
            tmpArray(selCount) = lBox.ItemData(i)
            
        End If
    Next

    If selCount = -1 Then
        '## If no items were selected, return an empty string
        GetSelectedItems = "" ' or "No items selected", etc.
    Else:
        '## Otherwise, return the array of items as a string,
        '   delimited by commas
        GetSelectedItems = Join(tmpArray, ", ")
    End If
End Function

Open in new window

Avatar of Bill Prew
Bill Prew

What specific line are you getting the error on?


»bp
Avatar of Aravind Ranganathan

ASKER

@ Bill Prew line number 6 on the where condition.
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial