Runtime error 'Too few parameters. Expected 1'

J

Julia B

Hi, got a strange problem.

I've got a form 'EditPartNumbers' where a user can filter the records by
selecting a value in a combo box, which in turn populates a value in a hidden
text box, 'txtFindHidden'. The form is then supposed to change it's
datasource to a query 'PartNumbersFine_EditForm', which has a parameter in
it's RecordID field which is [Forms]![EditPartNumber]![txtFindHidden].

If I select a record from the combo box and run the query directly from
Access it works fine, but if I try and run it through the following code, I
get an error:

'Run-time error -2147217904 (80040e10): Too few parameters. Expected 1.'

Here's the code:

Dim db As ADODB.Connection
Dim rs As New ADODB.Recordset
Set db = CurrentProject.Connection

'firstly get a recordset to check if there are any records
If formMode = "New" Then
rs.Open "PartNumbersNew_EditForm", db, adOpenKeyset,
adLockOptimistic, adCmdTableDirect
Else
'if the form isn't showing just new parts then get the recordset
depending on whether it's a find part or not
If findPart = "" Then
rs.Open "PartNumbersAll_EditForm", db, adOpenKeyset,
adLockOptimistic, adCmdTableDirect
Else
'this is where it stalls!
rs.Open "PartNumbersFind_EditForm", db, adOpenKeyset, adLockOptimistic,
adCmdTableDirect
End If
End If

I've searched and it would seem that the most common problem is a syntax
one, but I can't understand that it in this case.

Any ideas?

Thanks
Julia
 
J

Julia B

Thanks Chris, will look into this.

Chris O'C via AccessMonster.com said:
If the EditPartNumber form is open when the code runs, either the whatsit
field is missing from the PartNumbersNew_EditForm query or it's misspelled,
or the doodad table or query is missing (or misspelled) from the
PartNumbersNew_EditForm query.

Since the VBA procedure is incomplete (formMode and findPart are undefined
and not assigned any values), I'm inclined to think a field name (or table or
query name) is missing, rather than misspelled. But most of the time when
you see this error message, it's a misspelling or the query has misplaced
commas or spaces.

Chris
Microsoft MVP


Julia said:
Hi, got a strange problem.

I've got a form 'EditPartNumbers' where a user can filter the records by
selecting a value in a combo box, which in turn populates a value in a hidden
text box, 'txtFindHidden'. The form is then supposed to change it's
datasource to a query 'PartNumbersFine_EditForm', which has a parameter in
it's RecordID field which is [Forms]![EditPartNumber]![txtFindHidden].

If I select a record from the combo box and run the query directly from
Access it works fine, but if I try and run it through the following code, I
get an error:

'Run-time error -2147217904 (80040e10): Too few parameters. Expected 1.'

Here's the code:

Dim db As ADODB.Connection
Dim rs As New ADODB.Recordset
Set db = CurrentProject.Connection

'firstly get a recordset to check if there are any records
If formMode = "New" Then
rs.Open "PartNumbersNew_EditForm", db, adOpenKeyset,
adLockOptimistic, adCmdTableDirect
Else
'if the form isn't showing just new parts then get the recordset
depending on whether it's a find part or not
If findPart = "" Then
rs.Open "PartNumbersAll_EditForm", db, adOpenKeyset,
adLockOptimistic, adCmdTableDirect
Else
'this is where it stalls!
rs.Open "PartNumbersFind_EditForm", db, adOpenKeyset, adLockOptimistic,
adCmdTableDirect
End If
End If

I've searched and it would seem that the most common problem is a syntax
one, but I can't understand that it in this case.

Any ideas?

Thanks
Julia
 
J

Julia B

Have solved it as follows:

Me.RecordSource = "PartNumbersAll_EditForm"
If findPart = "" Then
DoCmd.showAllRecords
Else
DoCmd.ApplyFilter , "PNStored = '" + findPart + "'"
End If

Julia B said:
Thanks Chris, will look into this.

Chris O'C via AccessMonster.com said:
If the EditPartNumber form is open when the code runs, either the whatsit
field is missing from the PartNumbersNew_EditForm query or it's misspelled,
or the doodad table or query is missing (or misspelled) from the
PartNumbersNew_EditForm query.

Since the VBA procedure is incomplete (formMode and findPart are undefined
and not assigned any values), I'm inclined to think a field name (or table or
query name) is missing, rather than misspelled. But most of the time when
you see this error message, it's a misspelling or the query has misplaced
commas or spaces.

Chris
Microsoft MVP


Julia said:
Hi, got a strange problem.

I've got a form 'EditPartNumbers' where a user can filter the records by
selecting a value in a combo box, which in turn populates a value in a hidden
text box, 'txtFindHidden'. The form is then supposed to change it's
datasource to a query 'PartNumbersFine_EditForm', which has a parameter in
it's RecordID field which is [Forms]![EditPartNumber]![txtFindHidden].

If I select a record from the combo box and run the query directly from
Access it works fine, but if I try and run it through the following code, I
get an error:

'Run-time error -2147217904 (80040e10): Too few parameters. Expected 1.'

Here's the code:

Dim db As ADODB.Connection
Dim rs As New ADODB.Recordset
Set db = CurrentProject.Connection

'firstly get a recordset to check if there are any records
If formMode = "New" Then
rs.Open "PartNumbersNew_EditForm", db, adOpenKeyset,
adLockOptimistic, adCmdTableDirect
Else
'if the form isn't showing just new parts then get the recordset
depending on whether it's a find part or not
If findPart = "" Then
rs.Open "PartNumbersAll_EditForm", db, adOpenKeyset,
adLockOptimistic, adCmdTableDirect
Else
'this is where it stalls!
rs.Open "PartNumbersFind_EditForm", db, adOpenKeyset, adLockOptimistic,
adCmdTableDirect
End If
End If

I've searched and it would seem that the most common problem is a syntax
one, but I can't understand that it in this case.

Any ideas?

Thanks
Julia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top