View Single Post
  #1 (permalink)  
Old September 3rd, 2006, 06:55 PM
MMJiggy62 MMJiggy62 is offline
Registered User
Join Date: Jul 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default recordset open error

hi,i have a listbox which i'm facing problems with in storing its contents to its respective field in the database.code is as below, however an error occurred where it reads 'rs2.Open' statin that 'method or data member not found'...any help on this part? by the way, this is where i'm adding new records to my database.

Private sub cmdAdd_click()
Dim rs2 As Recordset
Dim strMyStr As String
Dim conn As New ADODB.Connection
Dim sSQL As String, sConn As String
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\legalminder1.mdb;Persist Security Info=False"

'        Set wk2 = DBEngine.CreateWorkspace("MyWks", "admin", "", dbUseJet)
'        Set db2 = wk2.OpenDatabase("c:\Project 1\legalminder1.mdb", False)
'       Set rs2 = db2.OpenRecordset("addrecord", dbOpenDynaset)
        On Error GoTo errHnd
        sSQL = "SELECT * FROM addrecord"
        Set conn = New ADODB.Connection
        'con.ConnectionString = sConn
        conn.Open sConn
        Set rs2 = New ADODB.Recordset
        rs2.Open sSQL, conn, adOpenStatic, adLockOptimistic

'        MsgBox "Add Record", vbInformation, "Record"
'        now we can add the record

        rs2.Fields(1).Value = UCase(txtDefineTask.Text)
        rs2.Fields(2).Value = UCase(txtDocuments.Text)
        rs2.Fields(3).Value = DTPicker1.Value
        rs2.Fields(4).Value = CInt(txtDays.Text)
        rs2.Fields(5).Value = UCase(txtNotes.Text)
'        here we first need to create a string
        rs2.Fields(6).Value = GetListItems()

'        lstAttach.AddItem NoNull(rs2.Fields(6).Value)

        txtDefineTask = ""
        txtDocuments = ""
        DTPicker1.Value = Date
        txtDays = ""
        txtNotes.Text = ""
        ' when we reach this point without any error we can do this msg
        MsgBox "Record added Successfully", vbInformation, "Record"
    End If

' The connection needs to be closed in any case- so we add this lines
    If rs2.State = adStateOpen Then
        Set rs2 = Nothing
    End If
    If conn.State = adStateOpen Then
        Set conn = Nothing
    End If
    Exit Sub
errHnd:             ' this is the entry point for errorhandler
    Call MsgBox(Err.Description, vbCritical + vbOKOnly, "Storing Data failed")
GoTo LeavePoint ' also closing connection in errorcase

 End Sub

Reply With Quote