Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA/ADO INSERT INTO Statement error...

Status
Not open for further replies.

SQLBI

IS-IT--Management
Jul 25, 2003
988
0
0
GB
Hi,

I'm trying to execute the following INSERT INTO Statement via ADO, however when i run the code i get an error message stating "Syntax Error in INSERT INTO Statement".

I can't see any problems so any help would be appreciated.

Code:
Private Sub cmdDiarySave_Click()

Dim dteDate As Date
Dim strUser As String
Dim lngClient As Long
Dim strText As Variant
Dim strSQL As String

dteDate = Me.txtDiaryDate
strUser = Me.txtDiaryUser
lngClient = Me.txtDiaryClientID
strText = Me.txtDiaryText

strSQL = "INSERT INTO tblDiary (ClientID, UserID, Date, Detail) " & _
          "VALUES(" & lngClient & ", '" & strUser & "', #" & dteDate & "#, '" & strText & "');"

Debug.Print
strSQL ***This looks ok in the immediate window.

Code:
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection

    cnn.Execute strSQL
***Falls over here


Code:
End Sub

Thanks in advance.

Leigh Moore
Solutions 4 MS Office Ltd
 
Could you try using Format$(dteDate,"d-mmm-yyyy") instead of dteDate.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top