I have a database with two different tables.
**call_code** activity
call_id activity_id
maintCall_plan activity_desc
maintCall_unplanned contact_person
creditCalls day
newBussCalls activity_date
phoneCalls revenue
time
I am having trouble debugging my code. The problem is syntax error in insert into
statement and conConnection.Execute
is highlighted. Here's my code snippet:
Private Sub Command1_Click()
Dim conConnection As ADODB.Connection
Dim cmdCommand As New ADODB.Command
Dim strSql As String
Set conConnection = New ADODB.Connection
conConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "\" & "db_weekActRep.mdb;Mode=Read|Write"
conConnection.CursorLocation = adUseClient
conConnection.Open
sqlStr = "INSERT INTO activity(activity_desc, contact_person, day, activity_date, revenue, time) VALUES ("
sqlStr = sqlStr & "'" & txtAct8am.Text & "',"
sqlStr = sqlStr & "'" & txtComp8am.Text & "',"
sqlStr = sqlStr & "'" & Label31.Caption & "',"
sqlStr = sqlStr & "'" & Label20.Caption & "',"
sqlStr = sqlStr & "'" & txtRev8am.Text & "',"
sqlStr = sqlStr & "'" & Label9.Caption & "')"
conConnection.Execute sqlStr
Select Case Combo1.ListIndex
Case 0
sqlStr = "INSERT INTO call_code(maintCall_plan) VALUES ("
sqlStr = sqlStr & "'" & "1" & "')"
conConnection.Execute sqlStr
Case 1
sqlStr = "INSERT INTO call_code(maintCall_unplanned) VALUES ("
sqlStr = sqlStr & "'" & "2" & "')"
conConnection.Execute sqlStr
Case 2
sqlStr = "INSERT INTO call_code(creditCalls) VALUES ("
sqlStr = sqlStr & "'" & "3" & "')"
conConnection.Execute sqlStr
Case 3
sqlStr = "INSERT INTO call_code(newBussCalls) VALUES ("
sqlStr = sqlStr & "'" & "4" & "')"
conConnection.Execute sqlStr
Case 4
sqlStr = "INSERT INTO call_code(phoneCalls) VALUES ("
sqlStr = sqlStr & "'" & "5" & "')"
conConnection.Execute sqlStr
End Select
End Sub
Also, I wanted to know if is it possible to insert data into two different tables using one click-event or button? If it is, am I doing it right?
By the way, I didn't include the activity_id
for the activity table because it is auto-incrementing. Same with the call_id
for the call_code
table. Any help would be much appreciated.