Variabele gebruiken

Status
Niet open voor verdere reacties.

RIANXL

Gebruiker
Lid geworden
7 feb 2007
Berichten
29
Hallo ik heb een probleempje waar ik wel vaker tegenaanloop.

Ik heb een variabele ( in dit geval "teller") die steeds veranderd.
ik wil deze variabele gebruiken met bijvoorbeeld: me.teller of rd!teller
dat zou dan rd!1, rd!2 enz. moeten worden

Weet er iemand of er een manier is om dit te noteren?
Want op deze manier werkt het niet.

Code:
Dim db As DAO.Database
Dim str As String
Dim rd As Recordset
Dim strLocation As String
Dim Teller As Integer
Dim Rij As Integer

strLocation = "X:/Database.mdb"
    Set db = OpenDatabase(strLocation)
        str = "SELECT roosterTMP.tmpID, roosterTMP.Dag, roosterTMP.RoosterID, roosterTMP.Week, " & _
        "roosterTMP.[0] , roosterTMP.[1], roosterTMP.[2], roosterTMP.[3], roosterTMP.[4], roosterTMP.[5], roosterTMP.[6], roosterTMP.[7], roosterTMP.[8], roosterTMP.[9], roosterTMP.[10], roosterTMP.[11], roosterTMP.[12], roosterTMP.[13], roosterTMP.[14], roosterTMP.[15], roosterTMP.[16], roosterTMP.[17], roosterTMP.[18], roosterTMP.[19]," & _
        "roosterTMP.[20], roosterTMP.[21], roosterTMP.[22], roosterTMP.[23], roosterTMP.[24], roosterTMP.[25], roosterTMP.[26], roosterTMP.[27], roosterTMP.[28], roosterTMP.[29], roosterTMP.[30], roosterTMP.[31], roosterTMP.[32], roosterTMP.[33], roosterTMP.[34], roosterTMP.[35], roosterTMP.[36], roosterTMP.[37], roosterTMP.[38], roosterTMP.[39]," & _
        "roosterTMP.[40], roosterTMP.[41], roosterTMP.[42], roosterTMP.[43], roosterTMP.[44], roosterTMP.[45], roosterTMP.[46], roosterTMP.[47], roosterTMP.[48], roosterTMP.[49], roosterTMP.[50], roosterTMP.[51], roosterTMP.[52], roosterTMP.[53], roosterTMP.[54], roosterTMP.[55], roosterTMP.[56] , roosterTMP.[57], roosterTMP.[58], roosterTMP.[59]," & _
        "roosterTMP.[60], roosterTMP.[61], roosterTMP.[62], roosterTMP.[63], roosterTMP.[64], roosterTMP.[65], roosterTMP.[66], roosterTMP.[67], roosterTMP.[68], roosterTMP.[69], roosterTMP.[70], roosterTMP.[71], roosterTMP.[72], roosterTMP.[73], roosterTMP.[74], roosterTMP.[75], roosterTMP.[76], roosterTMP.[77], roosterTMP.[78], roosterTMP.[79]," & _
        "roosterTMP.[80], roosterTMP.[81], roosterTMP.[82], roosterTMP.[83], roosterTMP.[84], roosterTMP.[85], roosterTMP.[86], roosterTMP.[87], roosterTMP.[88], roosterTMP.[89], roosterTMP.[90], roosterTMP.[91], roosterTMP.[92], roosterTMP.[93], roosterTMP.[94], roosterTMP.[95]" & _
        "FROM roosterTMP"
    Set rd = db.OpenRecordset(str)
        
    If rd.RecordCount <> 0 Then
        rd.MoveFirst
        Do While Not rd.EOF
[INDENT]        Rij = Rij + 1
        Worksheets("blad1").Rows(Rij).Columns(1) = rd!dag
        For Teller = 1 To 95
            [COLOR="Blue"]Worksheets("blad1").Rows(Rij).Columns(Teller + 4) =[/COLOR] [COLOR="Red"]rd![" & teller & "][/COLOR]
        Next Teller[/INDENT]
        rd.movenext
        loop
    Else

    End If
    
    rd.Close
    db.Close
 
ik neem aan dat je veldnamen nummers zijn, dus 1 ,2 ,3 enz. Dan zou dit het moeten doen:

Code:
Worksheets("blad1").Rows(Rij).Columns(Teller + 4) = rd((teller))

dus haakjes toevoegen. Even proberen en als het niet lukt laat het even weten. Vierkante haakjes moet je in ieder geval niet gebruiken.
 
Klasse:thumb: bedankt man ik kon het al nergens vinden. werkt prima zo!
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan