Hello all,
I'm trying to use a combobox pulldown menu with about 50 items listed in it from source "tblTO". Now I've got a command button right next to it. What I want to do is to have people select from the combobox one of the fifty items...and then hit the button next to it to delete it from the underlying table. I realized that I'd have to go with ADO in order to get it done so I started with this:
Private Sub Command5_Click()
'On Error GoTo Delete_Err
Dim CurConn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim CurDB As CurrentData
Dim cbb As ComboBox
Set CurDB = CurrentData
Set CurConn = New ADODB.Connection
Set cbb = Combo19
With CurConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
I'm getting the error in the next line...it won't let me call a connectionstring and says it doesn't recognize the CurrDB.name part
.ConnectionString = "data source= " & CurrDB.name
.Open
End With
Set rst = New ADODB.Recordset
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.Open "SELECT * FROM [tblTO] where [ROWA] = cbb"
With rst
.Delete
End With
rst.Close
Delete_exit:
Exit Sub
Delete_Err:
MsgBox "WRONG WRONG WRONG!!"
Resume Delete_exit
End Sub
So, the only problems I really have are the connection string and I will probably have a problem with calling the recordset open because I don't know the proper syntax for how to do that. If someone could help me out with the proper syntax to call open the rst and also the proper way to call the connectionstring I'd appreciate it greatly.
Also, if this can't be done or there is an easier way to do it (delete a record from a table with a combobox and button) please let me know...Maybe I'm doing too much for a simple thing. Thanks!
I'm trying to use a combobox pulldown menu with about 50 items listed in it from source "tblTO". Now I've got a command button right next to it. What I want to do is to have people select from the combobox one of the fifty items...and then hit the button next to it to delete it from the underlying table. I realized that I'd have to go with ADO in order to get it done so I started with this:
Private Sub Command5_Click()
'On Error GoTo Delete_Err
Dim CurConn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim CurDB As CurrentData
Dim cbb As ComboBox
Set CurDB = CurrentData
Set CurConn = New ADODB.Connection
Set cbb = Combo19
With CurConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
I'm getting the error in the next line...it won't let me call a connectionstring and says it doesn't recognize the CurrDB.name part
.ConnectionString = "data source= " & CurrDB.name
.Open
End With
Set rst = New ADODB.Recordset
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.Open "SELECT * FROM [tblTO] where [ROWA] = cbb"
With rst
.Delete
End With
rst.Close
Delete_exit:
Exit Sub
Delete_Err:
MsgBox "WRONG WRONG WRONG!!"
Resume Delete_exit
End Sub
So, the only problems I really have are the connection string and I will probably have a problem with calling the recordset open because I don't know the proper syntax for how to do that. If someone could help me out with the proper syntax to call open the rst and also the proper way to call the connectionstring I'd appreciate it greatly.
Also, if this can't be done or there is an easier way to do it (delete a record from a table with a combobox and button) please let me know...Maybe I'm doing too much for a simple thing. Thanks!