Updating Database Via ADO

c68

Board Regular
Joined
Nov 17, 2004
Messages
54
I'm using a latebinding method to update a table via a user form, but keep getting an error message saying "Syntax error in From clause." I'm not sure what it is that I'm doing wrong here. Below is my code. Any help would greatly appreciated.

Const adUseServer = 2
Const adOpenDynamic = 2
Const adLockOptimistic = 3
Const adCmdTable = 2

Sub UpdateRoutineTable()
Dim rst As Object
Dim cn As Object
Dim d As Double
Dim x As Double

Set rst = CreateObject("ADODB.Recordset")
Set cn = CreateObject("ADODB.Connection")

If Routine.Analyst = "" Or Routine.Tasks = "" Or _
Routine.hrs = "" Or Routine.Mins = "" Or Routine.DateCompleted = "" Then
MsgBox "Please populate all fields and try again.", vbOKOnly, "Missing Fields"
Exit Sub

Else

d = Routine.hrs + (Routine.Mins / 60)
x = Routine.rptID
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = tmtPath
.Open
End With

rst.CursorLocation = 2
rst.Open Source:="Select * From RoutineTable WHERE Reporting_ID=" & x, _
ActiveConnection:=cn, _
CursorType:=2, _
LockType:=3, _
Options:=2

With rst
!Due_Date = Routine.dueDate2
!Date_Updated = Routine.DateCompleted
!Date_Entered = Now
!Durration = d
!UpdatedBy = Application.UserName
.Update
End With
End If

rst.Close
cn.Close

Set rst = Nothing
Set cn = Nothing
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
The problem has been solved. I had missed placing the "adOpenKeySet" to 1. Thank you all.
 
Upvote 0

Forum statistics

Threads
1,224,604
Messages
6,179,857
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top