Error in Code - never had this before - Run-time error '3061':

B

BlueWolvering

Hello,
This is a repost because I thought I received a fix but I did not.

This is still broken.

I have used this code before countless times to find records in a
table/query within in VBA. (Using Access 2003).

Here is the code
Dim MyDb As Database, RS As Recordset, TargetQueryName as String
TargetQueryName = "q_VINRESULTS_find_FuelCard"
Set MyDb = CurrentDb
-->Set RS = MyDb.OpenRecordset(TargetQueryName)

RS.MoveFirst
If IsNull(RS.Fields(0).Value) Then
MsgBox "This fuel card is currently unassigned.", vbCritical,
"Unassigned Fuel Card"

Else
VINnum = RS.Fields(0).Value
DoCmd.OpenForm "f_VinResults"
End If

The arrow indicates the line on which the code fails. here is the error
message.
<<<Run-time error '3061':

Too few parameters. Expected 2.>>>

Here is the SQL for the query.
SELECT t_FuelCardInventory.VIN, t_FuelCardInventory.FuelCardNo,
t_FuelCardInventory.FuelCardProvider
FROM t_FuelCardInventory
WHERE (((t_FuelCardInventory.FuelCardNo)=[Forms]![f_SearchPanel]![FCN1]) AND
((t_FuelCardInventory.FuelCardProvider)=[Forms]![f_SearchPanel]![FCP1]));


The goal of this code is to take Fuel Card No and Fuel Card Provider from
the form, find out which VIN they are assigned to, and then shove that Vin
into VINum on the form.

Thanks
 
B

BlueWolvering

Dim MyDb As Database, RS As Recordset
Dim TQN As String
TQN = "SELECT t_FuelCardInventory.VIN, t_FuelCardInventory.FuelCardNo,
t_FuelCardInventory.FuelCardProvider " & _
"FROM t_FuelCardInventory " & _
"WHERE (((t_FuelCardInventory.FuelCardNo)='" &
[Forms]![f_SearchPanel]![FCN1] & "') AND
((t_FuelCardInventory.FuelCardProvider)='" & [Forms]![f_SearchPanel]![FCP1] &
"'));"
MsgBox TQN
Set MyDb = CurrentDb
Set RS = MyDb.OpenRecordset(TQN)

RS.MoveFirst
If IsNull(RS.Fields(0).Value) Then
MsgBox "This fuel card is currently unassigned.", vbCritical,
"Unassigned Fuel Card"

Else
VINnum = RS.Fields(0).Value
DoCmd.OpenForm "f_VinResults"
End If

Through another forum, I found the idea to use SQL within VBA to solve the
problem. This code works flawlessly.

Thanks for the help!
 

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