I've some code in Excel that updates an Access table based on if RTP_ID equals IngID, the following matches and works if they are numeric in RTP_ID:
sSQL = "SELECT * FROM Tbl_Primary WHERE RTP_ID = " & lngID
However I would like it where RTP_ID
could be a string.
I've tried:
sSQL = "SELECT * FROM Tbl_Primary WHERE RTP_ID = '" & lngID & "'"
but that still doesn't work, any ideas?
So if RTP_ID
was 1
it would work, but if it was 1A
it wouldn't.
Edit- here is the code I currently have:
Application.ScreenUpdating = False
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Dim MyConn
Dim lngRow As Long
Dim lngID, LR, Upd
Dim strID As String
Dim j As Long
Dim sSQL As String
LR = Range("B" & Rows.Count).End(xlUp).Row
Upd = LR - 1
lngRow = 2
Do While lngRow <= LR
strID = Cells(lngRow, 2).Value
sSQL = "SELECT * FROM Tbl_Primary WHERE RTP_ID2 = " & strID
Set cnn = New ADODB.Connection
MyConn = "Provider = Microsoft.ACE.OLEDB.12.0;" & _
"Data Source =\Work\Sites\HLAA\NEW\test\HLAA 2015 NEW.mdb"
With cnn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Open MyConn
End With
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseServer
rst.Open sSQL, ActiveConnection:=cnn, _
CursorType:=adOpenKeyset, LockType:=adLockOptimistic
.
With rst
.Fields("MonitorCapacity") = Cells(lngRow, 74).Value
rst.Update
End With
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
lngRow = lngRow + 1
Loop
MsgBox "You just updated " & Upd & " records"