variable in quotes

kiwi

New member
Local time
Today, 22:44
Joined
Feb 4, 2009
Messages
2
Hi,
I am returning to an access project after a break of quite a few years. I am struggling with the following code!
if i call
showmethechildren(114100)
it works fine if the variable is a string then it only works if it is in quotes i.e
showmethechildren("NIP21234114100") works
showmethechildren(NIP21234114100) doesn't
Thanks for any help


Public Sub showmethechildren(strParpart As String)
Dim db As Database
Dim rstchilds As Recordset
Dim sqlstr1 As String

Set db = CurrentDb
sqlstr1 = "SELECT PARTS_List.[Component_No], MASTER.[Description], PARTS_List.[Parent_No], PARTS_List.[Qty_Per], PARTS_List.[Qty_Per_A] " & _
"FROM PARTS_List INNER JOIN MASTER ON PARTS_List.[Component_No] = MASTER.[Part_No] " & _
"WHERE PARTS_List.[Parent_No] =" & Chr(34) & strParpart & Chr(34) & ";"

Set rstchilds = db.OpenRecordset(sqlstr1)

If rstchilds.RecordCount > 0 Then

Debug.Print rstchilds.RecordCount

With rstchilds
rstchilds.MoveFirst
Do Until .EOF
Debug.Print strParpart, rstchilds![Component_No], " ", rstchilds![Description], " ", " ", rstchilds![Qty_Per]
.MoveNext
Loop
End With
Else
Debug.Print "no data to manipulate"
End If
rstchilds.Close
End Sub
 
That is because text strings need to be in quotes.... so showmethechildren("NIP21234114100") is the only proper way to do it.
 
Public Sub showmethechildren(strParpart As String)

you are calling the sub showmethechildren

which requires an argument of type string

hence you cannot correctly pass a numeric argument

you either need to pass an explicit string (ie in quote marks) or more likely a variable which is typed as a string
 

Users who are viewing this thread

Back
Top Bottom