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
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