Can someone help me with this code. The sql code has bugs in it I have tried to figure out for a week
without success. When I delete out a record the navigation buttons do not work right.
And when I insert the record the record doesn't show up until I exit out and then come
back into the program. With an initial insert it gives the message 'The option requested is not allowed in this context.
I apologize for the code looking like crap but I am new to ADO so please forgive.
John
Option Explicit
Dim cnAP As Connection
Dim rsSchool As Recordset
Dim sbAddNew As Boolean
Dim cmdSchool As Command
Private Sub Form_Load()
Set cnAP = New Connection
Set rsSchool = New Recordset
Set cmdSchool = New Command
cnAP.Open "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;........
rsSchool.Open "SELECT * FROM SCHOOL ORDER BY KEY", _
cnAP, adOpenKeyset, adLockOptimistic, adCmdText
SetNavigationButtons True
End Sub
Private Sub cmdInsert_Click()
On Error GoTo errorhandler
Dim dr As Long
Dim cnn As ADODB.Connection
Dim SQL As String
Dim cmdSchool As Command
Set cnn = New Connection
Set cmdSchool = New Command
cnAP.CursorLocation = adUseClient
cnAP.BeginTrans
cnn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\project\Student.mdb"
cmdSchool.ActiveConnection = cnAP
cmdSchool.CommandType = adCmdText
SQL = "INSERT INTO School(Key,Schoolid,Name,Principal,Telephone) " & _
"VALUES('26','100','Private School','Jones','N/A')"
cmdSchool.CommandText = SQL
cmdSchool.Execute
cnAP.CommitTrans
Private Sub cmdDelete_Click()
Dim dr As Long
Dim cnn As ADODB.Connection
Dim constr As String
Dim SQL As String
Dim errloop As ADODB.Error
constr = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\project\Student.mdb"
Set cnn = New ADODB.Connection
cnn.Open constr
cnn.BeginTrans
If cnn.Errors.Count > 0 Then
MsgBox "An error has occured"
For Each errloop In cnn.Errors
MsgBox "Error #: " & errloop.Number & vbCr & _
errloop.Description
Next
cnn.RollbackTrans
Exit Sub
End If
dr = InputBox("Enter the Schoolid you want to delete", "Delete School"
SQL = "DELETE FROM SCHOOL WHERE SCHOOL!KEY = " & dr & ""
cnn.Execute SQL
cnn.CommitTrans
End Sub
without success. When I delete out a record the navigation buttons do not work right.
And when I insert the record the record doesn't show up until I exit out and then come
back into the program. With an initial insert it gives the message 'The option requested is not allowed in this context.
I apologize for the code looking like crap but I am new to ADO so please forgive.
John
Option Explicit
Dim cnAP As Connection
Dim rsSchool As Recordset
Dim sbAddNew As Boolean
Dim cmdSchool As Command
Private Sub Form_Load()
Set cnAP = New Connection
Set rsSchool = New Recordset
Set cmdSchool = New Command
cnAP.Open "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;........
rsSchool.Open "SELECT * FROM SCHOOL ORDER BY KEY", _
cnAP, adOpenKeyset, adLockOptimistic, adCmdText
SetNavigationButtons True
End Sub
Private Sub cmdInsert_Click()
On Error GoTo errorhandler
Dim dr As Long
Dim cnn As ADODB.Connection
Dim SQL As String
Dim cmdSchool As Command
Set cnn = New Connection
Set cmdSchool = New Command
cnAP.CursorLocation = adUseClient
cnAP.BeginTrans
cnn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\project\Student.mdb"
cmdSchool.ActiveConnection = cnAP
cmdSchool.CommandType = adCmdText
SQL = "INSERT INTO School(Key,Schoolid,Name,Principal,Telephone) " & _
"VALUES('26','100','Private School','Jones','N/A')"
cmdSchool.CommandText = SQL
cmdSchool.Execute
cnAP.CommitTrans
Private Sub cmdDelete_Click()
Dim dr As Long
Dim cnn As ADODB.Connection
Dim constr As String
Dim SQL As String
Dim errloop As ADODB.Error
constr = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\project\Student.mdb"
Set cnn = New ADODB.Connection
cnn.Open constr
cnn.BeginTrans
If cnn.Errors.Count > 0 Then
MsgBox "An error has occured"
For Each errloop In cnn.Errors
MsgBox "Error #: " & errloop.Number & vbCr & _
errloop.Description
Next
cnn.RollbackTrans
Exit Sub
End If
dr = InputBox("Enter the Schoolid you want to delete", "Delete School"
SQL = "DELETE FROM SCHOOL WHERE SCHOOL!KEY = " & dr & ""
cnn.Execute SQL
cnn.CommitTrans
End Sub