I have a field in a recordset which is a string. It can look like
this: 13-15-67-56
I need to break out this string into numbers to run in queries to open
recordsets.
But when I try to open the recordset I get the data conversion error
3421.
I have tried using the format function to convert the string and it
doesn't work. But if I get the strSQL statement from the Immediate
window and paste it into a query it works fine with no errors.
Here's some of the code:
With rstSearchTable
If .RecordCount > 0 Then
.MoveFirst
strSubBrands = ""
srchPos = InStr(!SubBrandSK, "-")
'See if there is more than one subBrand
If srchPos > 0 Then
strSubBrands = Left(!SubBrandSK, srchPos - 1)
'Dim newsubbrand As Long
'newsubbrand = Format(strSubBrands, "General Number")
'newsubbrand = Format(strSubBrands, "standard")
Do Until .EOF
'Get subBrands
' strSQL = "SELECT * FROM Brand WHERE SK = " & newsubbrand
& ";"
strSQL = "SELECT * FROM Brand WHERE SK = " & strSubBrands
& ";"
'strSQL = "SELECT * FROM Brand WHERE SK = " &
Format(strSubBrands, "Standard") & ";"
Set rstSubBrands = .OpenRecordset(strSQL, dbOpenDynaset)
Loop
.MoveNext
Else
strSQL = "SELECT * FROM Brand WHERE SK = " & strSubBrands &
";"
Set rstSubBrands = .OpenRecordset(strSQL, dbOpenDynaset)
End If
End If
End With
I left some of the commented out code in there to show what I've been
trying.
Any help would be greatly appreciated.