rpaulson
Well-known Member
- Joined
- Oct 4, 2007
- Messages
- 1,415
Hello all,
my first try at writing VBA to add data to Access table.
I am not happy with the code i created, it works, but it does not appear to a good method, especially if there are many fields in my table.
I have to believe there is an easier way to insert \ update.
thanks for looking,
Ross
my first try at writing VBA to add data to Access table.
I am not happy with the code i created, it works, but it does not appear to a good method, especially if there are many fields in my table.
I have to believe there is an easier way to insert \ update.
VBA Code:
...
UserID = 66
Fname = "Tim"
Lname = "Jones"
Phone = "212-555-1212"
On Error GoTo 888 'i need this to avoid an error if the recordlready exists
strSQL = "INSERT INTO users (userID,Fname,Lname,Phone) VALUES (" & UserID & ",'" & Fname & "','" & Lname & "'," & Phone & ")" 'add new record
objConn.Execute strSQL
888
On Error Resume Next
strSQL = "UPDATE users SET Fname='" & Fname & "',Lname='" & Lname & "',Phone='" & Phone & "' WHERE userID =" & UserID 'update an exusting record.
objConn.Execute strSQL
...
thanks for looking,
Ross