RAYLWARD102
Well-known Member
- Joined
- May 27, 2010
- Messages
- 529
I'm successfully writing values to an access DB table. At different points in my Excel VBA project, I may need to refer back to records stored in the access database for change from excel vba. I've been playing with the syntax, but can't seem to make a go of it. I'll post what I've got thus far.
I want to search the "TransactionSorting" table, column field "bins" for a value of 137. IF found, I would like to remove\clear the value.
I want to search the "TransactionSorting" table, column field "bins" for a value of 137. IF found, I would like to remove\clear the value.
Code:
Sub mrexcel()
Set cont = Sheets("controls")
strig = cont.Range("p15").Value & cont.Range("p16").Value 'file path and filename
On Error Resume Next
Set db = OpenDatabase(strig)
Set rs = db.OpenRecordset("TransactionsSorting", dbOpenTable)
i = "137" 'later to be supplied with variable
With rs
rs.MoveFirst
While Not rs.EOF
If rs.Fields("bins").Value = i Then
rs.Fields("bins").Value = ""
rs.Update
rs.MoveNext
Else:
rs.MoveNext
End If
Wend
End With
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Sub