Avatar billede svuppenator Nybegynder
25. september 2002 - 11:45 Der er 10 kommentarer

MOVELAST

Hvorfor må jeg ikke lave en movelast
VB siger: "Object Variable or with block variable not set"
-------------------------------------------------------
Private Sub Oktour_Click()
    Dim rs As ADODB.Recordset
    Dim rs2 As ADODB.Recordset
    Dim str As String
    Dim str2 As String
    Dim tourid As Integer
   
    eksitour = TourCombo.Text
   
   
    If eksitour = "" Then
        tournavn = Text1.Text
        distance = Int(Text2.Text)
       
        str = "INSERT INTO Tour(Navn, Distance, Samletkr, AntalDeltagere, Voksne, Born) VALUES('" & tournavn & "'," & distance & ", 0,0,0,0)"
        sql.SQLConn
        Call sql.rsExecute(str)
        sql.Disconnect
        Text1.Text = ""
        Text2.Text = ""
       
        str2 = "SELECT TourID FROM Tour"
        sql2.SQLConn
        rs.MoveLast <---------------------- FEJLEN!!
        Set rs2 = sql2.rsSelect(str2)
        funcs.tourid = rs2("TourID")
        MsgBox funcs.tourid
        sql2.Disconnect
        Form2.Enabled = False
        Form2.Visible = False
    Else
        tourid = Mid(TourCombo.Text, 1, 2)
       
        str = "SELECT TourID FROM Tour WHERE TourID = " & tourid
       
        sql.SQLConn
        Set rs = sql.rsSelect(str)
        funcs.tourid = rs("TourID")
        MsgBox funcs.tourid
        sql.Disconnect
        Form2.Enabled = False
        Form2.Visible = False
    End If
   
End Sub
------------------------------------------------------

min SQL klasse:
-------------------------------------------------------
Option Explicit
'connection variable
Dim cn As New ADODB.Connection
Dim tmp As String
Public Sub SQLConn()
    cn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\data.mdb"
End Sub

Public Sub Disconnect()
'Lukker forbindelsen
cn.Close
End Sub

Public Function rsSelect(record As String) As ADODB.Recordset
'Bruges når man skal hente noget fra en tabel
Dim rs As ADODB.Recordset

tmp = record

'initialiserer recordset
Set rs = New ADODB.Recordset

'Åben recordset
rs.Open tmp, cn

Set rsSelect = rs

End Function

Public Sub rsExecute(record As String)
'Bruges når man skal indsætte,update eller slette noget fra en tabel.
    Dim rs As ADODB.Recordset

    tmp = record

    'initialiserer recordset
    Set rs = New ADODB.Recordset

    'Åben recordset
    rs.Open tmp, cn
End Sub
-----------------------------------------------------
Avatar billede terry Ekspert
25. september 2002 - 11:50 #1
where are you setting teh rs Recordset?
Avatar billede svuppenator Nybegynder
25. september 2002 - 11:54 #2
på den her måde ADODB.Recordset
Avatar billede svuppenator Nybegynder
25. september 2002 - 11:54 #3
dete r måske ikke nok??
Avatar billede terry Ekspert
25. september 2002 - 11:54 #4
you need to place
Dim rs As ADODB.Recordset
at the top of the module OUTSIDE the sub, at the moment you have THREE rs recordsets and as far as I can see this one is NOT getting set

rs.MoveLast <---------------------- FEJLEN!!
Avatar billede svuppenator Nybegynder
25. september 2002 - 11:58 #5
ok... nu har jeg sat Dim rs As ADODB.Recordset op i toppen men nu får jeg en fejl: "Operation not allowed when object is closed"
Avatar billede terry Ekspert
25. september 2002 - 11:58 #6
the function rsSelect returns a records BUT it is NOT called until AFTER the error.
The function rsExecute DOES NOT return a recordset, it doesnt do much at all in fact!
So I suggest you take a VERY carefull look at your code and decide what it is your trying to do. Then do one thing at a time and get that working first before going onto the next step.
Avatar billede terry Ekspert
26. september 2002 - 08:25 #7
Hows it going with this question?
Avatar billede svuppenator Nybegynder
26. september 2002 - 11:24 #8
jeg har fået fikset en del og nu siger den at "Rowset does not support fetching backward"

ændret kode...
---------------------------------------------------------------------------
Dim cn As New ADODB.Connection
Private Sub Oktour_Click()
    Dim rs As ADODB.Recordset
    Dim rs2 As ADODB.Recordset
   
    Dim str As String
    Dim str2 As String
    Dim tourid As Integer
   
    cn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\data.mdb"
   
    Set rs = New ADODB.Recordset
    Set rs2 = New ADODB.Recordset
   
    eksitour = TourCombo.Text
   
   
    If eksitour = "" Then
        tournavn = Text1.Text
        distance = Int(Text2.Text)
       
        str = "INSERT INTO Tour(Navn, Distance, Samletkr, AntalDeltagere, Voksne, Born) VALUES('" & tournavn & "'," & distance & ", 0,0,0,0)"
        sql.SQLConn
        Call sql.rsExecute(str)
        sql.Disconnect
        Text1.Text = ""
        Text2.Text = ""
       
        str2 = "SELECT TourID FROM Tour"
        rs2.Open str2, cn
        rs2.MoveLast
        funcs.tourid = rs2("TourID")
        MsgBox funcs.tourid
        Form2.Enabled = False
        Form2.Visible = False
        ...
--------------------------------------------------------------------------
Avatar billede terry Ekspert
26. september 2002 - 20:56 #9
I suggest you take a look at this link, not all recordsets support moving backwards so it is more than likley the way you are opening the recordset.
Avatar billede svuppenator Nybegynder
26. september 2002 - 21:11 #10
uhm... du har glemt at skrive linket...
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester