hi everyone, got a problem with my update to a database. the problem is i want to do an insert in two tables that are related using one command button. the first table- admin-updates, but the second one does not. it seems they cannot use the same connection
CODE
Dim cConn As ADODB.Connection
Dim rsAdmin As ADODB.Recordset
Dim Rx As Long, xCount As Integer
Private Sub EnableControls()
Dim MyControl As Control
For Each MyControl In Controls
If TypeOf MyControl Is TextBox Then
MyControl.Enabled = True
End If
Next
End Sub
Private Sub cmdexit_Click()
Unload Me
End Sub
Private Sub cmdsave_Click()
With rsAdmin
.Open "select * from Admin", cConn, adOpenKeyset, adLockOptimistic
.AddNew
rsAdmin!Admin_no = txtadmin_no.Text
rsAdmin!first_name = txtfirstname.Text
rsAdmin!last_name = txtlastname.Text
rsAdmin!department = txtdepartment.Text
.Update
.Requery
MsgBox "Update Completed"
.Close
End With
End Sub
Private Sub Form_Load()
frmadd.Show
OpenConnection App.Path & "\ExamRegistration.mdb"
'Call ClearControls
Call DisableControls
Dim strEntry As Integer
strEntry = Val(InputBox("Enter the Administrator number"))
rsAdmin.Open "select * from Admin where Admin_no=" & strEntry, cConn, adOpenKeyset, adLockOptimistic
With rsAdmin
If .BOF = True And .EOF = True Then
Call ClearControls
Call EnableControls
txtadmin_no = strEntry
txtfirstname.SetFocus
Else
txtadmin_no.Text = rsAdmin![Admin_no] & ""
txtfirstname.Text = rsAdmin!first_name & ""
txtlastname.Text = rsAdmin!last_name & ""
txtdepartment.Text = rsAdmin!department & ""
MsgBox "Record already exists"
'Exit Sub
End If
.Close
End With
End Sub
Private Sub ClearControls()
Dim MyControl As Control
For Each MyControl In Controls
If TypeOf MyControl Is TextBox Then
MyControl.Text = ""
End If
Next
End Sub
Private Sub DisableControls()
Dim MyControl As Control
For Each MyControl In Controls
If TypeOf MyControl Is TextBox Then
MyControl.Enabled = False
End If
Next
End Sub
Private Sub OpenConnection(strPath As String)
' Close on open connection
If Not (cConn Is Nothing) Then
cConn.Close
Set cConn = Nothing
End If
'Create an instance of connection
Set cConn = New ADODB.Connection
'create an instance of recordset object
Set rsAdmin = New ADODB.Recordset
'set the cursor location
cConn.CursorLocation = adUseClient
' Open a new connection
cConn.Open "Provider=microsoft.jet.OLEDB.4.0;" _
& "Data source= " & strPath
End Sub
please help