Kevin,
I strongly agree with Cassie.
I make it a bit easier by creating the string used for the connection in the first forms load event as such:
Private Sub Form_Load()
If constr & "" = "" Then
constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\StudentTracking.mdb;Persist Security Info=False"
End If
End Sub
Constr is defined as a string in a module common to the application.
The following is a delete subroutine which shows how this works.
Private Sub DelButton_Click()
Dim con As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sCMD As String
Dim sSQL As String
If MSHFlexGrid1.RowSel < 1 Then
Call MsgBox("You must pick a row to delete", vbInformation, App.Title)
Exit Sub
End If
Set con = New ADODB.Connection
con = constr
con.Open
MSHFlexGrid1.Col = 0
sCMD = "delete * from tblstudents where pkstudent = " & MSHFlexGrid1.Text
con.Execute sCMD, , adCmdText
sSQL = "select PKStudent,LastName,FirstName,MI,DOB,Gender from tblstudents"
Set rst = New ADODB.Recordset
rst.Open sSQL, con, adOpenStatic, adLockOptimistic
Set MSHFlexGrid1.Recordset = rst
rst.Close
con.Close
Set rst = Nothing
Set rst = Nothing
End Sub
Notice that both the new recordset and the new connection are both closed and set to nothing.
Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@earthlink.net