p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Beginning VB 6 (http://p2p.wrox.com/forumdisplay.php?f=75)
-   -   recordset open error (http://p2p.wrox.com/showthread.php?t=47330)

MMJiggy62 September 3rd, 2006 06:55 PM

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

dpkbahuguna September 3rd, 2006 11:11 PM

Frnd I think you forgot to use the ADODB Class in initialization


   Dim rs2 As ADODB.Recordset = Dim rs2 As Recordset


MMJiggy62 September 4th, 2006 04:52 PM

hey thanks, got that!

All times are GMT -4. The time now is 06:17 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.