Help with SQL insert

associates

Registered User.
Local time
Today, 00:19
Joined
Jan 5, 2006
Messages
94
Hi,

I need urgent help. I have a question to ask and wonder if anyone might be able to help me.

My question is how do i execute SQL insert into a table called Job Register in access.

Here is my code before update

If foundflag = False Then
'new job detected
StrSQL = "INSERT INTO [Job Register](Industry_No, Client_No, Job_No, Job_Name, Job_Contact, Job_Phone, Job_MPhone, Job_Fee, Job_Reference, Job_Manager, Date_Registered) "
StrSQL = "VALUES ('" & Me.Combo20 & "', '" & Me.Text2 & "', '" & Me.Text4 & "', '" & Me.Text8 & "', '" & Me.Text10 & "', '" & Me.Text12 & "', '" & Me.Job_Mphone & "', '" & Me.Text14 & "', '" & Me.Text16 & "', '" & Me.Job_Manager & "', '" & Me.Date_Registered & "')"

End If

Your help is greatly appreciated.

Thank you very much in advance
 
Thank you, Pat Hartman

SOrry i don't get your first comment in regards to enclose the date in #'s.

However, i've been struggling to execute the sql insert. Here is my code

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim mesg, TITLE As String
Dim foundflag As Boolean
Dim StrSQL As String
Dim WorkBase As Database
Dim WorkRS1 As Recordset

foundflag = False

mesg = "Data has been changed in this record. Do you want to proceed?"
TITLE = "Warning !!!"

If MsgBox(mesg, vbYesNo, TITLE) = vbNo Then
Cancel = True 'if user respond is No, then don't do updating
Me.Undo 'then undo all the data and reset the beforeupdate event
Else
'check if job is a new job
Dim rsNew As New ADODB.Recordset

rsNew.Open "Select * from [SubJob Register]", CurrentProject.Connection, adOpenDynamic, adLockOptimistic

Do Until rsNew.EOF
If rsNew!Industry_No = Me.Combo20 Then
MsgBox "industry found"
If rsNew!Client_No = Me.Text2 Then
MsgBox "client found"
If rsNew!Job_No = Me.Text4 Then
MsgBox "found Job"
foundflag = True
End If
End If

Exit Do
End If

rsNew.MoveNext
Loop

rsNew.Close

If foundflag = False Then
MsgBox "New Job"
Set WorkBase = CurrentDb
'new job detected
StrSQL = "INSERT INTO [Job Register](Industry_No, Client_No, Job_No, Job_Name, Job_Contact, Job_Phone, Job_MPhone, Job_Fee, Job_Reference, Job_Manager, Date_Registered) "
StrSQL = StrSQL + "VALUES ('" & Me.Combo20 & "', '" & Me.Text2 & "', '" & Me.Text4 & "', '" & Me.Text8 & "', '" & Me.Text10 & "', '" & Me.Text12 & "', '" & Me.Job_Mphone & "', '" & Me.Text14 & "', '" & Me.Text16 & "', '" & Me.Job_Manager & "', '" & Me.Date_Registered & "')"

Set WorkRS1 = WorkBase.Execute(StrSQL)
WorkRS1.Close
WorkBase.Close
End If

End If
End Sub

The error message is expected function or variable around the workbase.execute(StrSQL).

Thank you in advance
 

Users who are viewing this thread

Back
Top Bottom