I am trying to set up some code to add records to a linking table based on a couple of parameters from the form, using VB in Access Form, SQL backend.
I created the linking table (Diary_tb) from SQL server as:
NUMBER nvarchar 8 primary key
DETAILS nvarchar 50 allowed null
STARTDATE smalldatetime 4 primary key
FINISHDATE smalldatetime 4 allowed null
TYPE nvarchar 20 primary key
My code is:
Private Sub RNKINDX_AfterUpdate()
Dim strMsg As String
Dim strInput As String
Dim dteStart As Date
Dim strDetail
Dim STARTDATE As Date
strMsg = "Do you want to promote the new rank ?"
If MsgBox(strMsg, vbOKCancel, "Error!" = vbOK Then
newRank = Me![RANK]
strInput = InputBox("Please input promotion date"
STARTDATE = CDate(strInput)
strDetail = oldRank + newRank
Set dbs = CurrentDb
strSQL = "INSERT INTO DIARY_tb (NUMBER, DETAILS, STARTDATE, TYPE) VALUES ('" & Trim(Me![NUMBER]) & "','" & strDetail & "', #" & STARTDATE & "#, 'PROMOTION');"
DoCmd. RunSQL strSQL
Else
Exit Sub
End If
End Sub
After I run this code I got error message:
Run-time Error 3134
Syntax error in INSERT INTO statement.
Many thanks for any help.
Cathy
I created the linking table (Diary_tb) from SQL server as:
NUMBER nvarchar 8 primary key
DETAILS nvarchar 50 allowed null
STARTDATE smalldatetime 4 primary key
FINISHDATE smalldatetime 4 allowed null
TYPE nvarchar 20 primary key
My code is:
Private Sub RNKINDX_AfterUpdate()
Dim strMsg As String
Dim strInput As String
Dim dteStart As Date
Dim strDetail
Dim STARTDATE As Date
strMsg = "Do you want to promote the new rank ?"
If MsgBox(strMsg, vbOKCancel, "Error!" = vbOK Then
newRank = Me![RANK]
strInput = InputBox("Please input promotion date"
STARTDATE = CDate(strInput)
strDetail = oldRank + newRank
Set dbs = CurrentDb
strSQL = "INSERT INTO DIARY_tb (NUMBER, DETAILS, STARTDATE, TYPE) VALUES ('" & Trim(Me![NUMBER]) & "','" & strDetail & "', #" & STARTDATE & "#, 'PROMOTION');"
DoCmd. RunSQL strSQL
Else
Exit Sub
End If
End Sub
After I run this code I got error message:
Run-time Error 3134
Syntax error in INSERT INTO statement.
Many thanks for any help.
Cathy