Runtime Error 3061 in Acc2010

Heidestrand

Registered User.
Local time
Today, 09:20
Joined
Apr 21, 2015
Messages
73
Hello,

I've a problem in Access. Every time I perform a SQL query to write the result of the query into a text-field I get a run time error 3061 : Too few parameters. Expected 1.

This is my code:
Code:
Private Sub Text0_AfterUpdate()
    Dim str As String, strSQL As String
    
    str = Me!Text0.Text
 
    strSQL = "SELECT Endkundenadresse" _
      & " FROM tblDatenAusExcelNeu-2" _
      & " WHERE Verkaufsbeleg='" & str & "'"
      
    Me!Text2 = CurrentDb.OpenRecordset(strSQL)(0)
End Sub

But I have no idea how to solve it. Can someone help me?
 
Try

SELECT Endkundenadresse" .* FROM tblDatenAusExcelNeu-2 WHERE (((Verkaufsbeleg.Endkundenadresse) ='" & str & "'))"
 
currentdb opens a recordset, Me!text2 is a control, not a recordset

it will also fail if text0 has not been completed

probably easier if you use the Dlookup function

Text2=DLookup("Endkundenadresse","tblDatenAusExcelNeu-2","Verkaufsbeleg='" & str & "'")
 
Thanks a lot for you two reply's!

The solution provided by CJ_London works perfectly, this is that I was looking for. I was also reading something in the meantime that assigning an SQL query to a text-field isn't a good idea respectively a text-field isn't suitable for this.
Better to use is DLookUp() in this case. I also stumbled upon this function but couldn't manage to apply it correctly. Now it works. Thanks! :)
 

Users who are viewing this thread

Back
Top Bottom