skrev i meddelandet
> Hi all,
>
> I have an MS Access database with just one table. In that table are
> several dozen columns, each one called Variable1, Variable2,
> Variable3, etc.
>
> Is there any way to use a For/Next loop to write information to this
> table? For example, if I wanted to write data to just one variable, I
> could use this: MyDatabase!Variable1 = [whatever value].
>
> What I'm trying to do is write all of the variables at once, using
> something like this:
>
> For b = 1 to 100
> MyDatabase!Variable"(b)" = [whatever value].
> Next b
>
> Obviously this code doesn't work, but I'm wondering whether someone
> knows how I can accomplish this.
>
> Thanks,
> Rob
>
If using SQL queries, this works that way (filter out what you need)
With SkoRent(sc)
tmp = .Antal
If .QueNr > 0 Then
strSQL = "UPDATE orders SET " _
& "pnr=""" & .PersNr & """, " _
& "tel=""" & .Phone & """, " _
& "adress=""" & .Adress & """, " _
& "comment=""" & .Comment & """, " _
& "datum=""" & .Datum & """, " _
& "antal=" & .Antal
For i = 1 To 10
If tmp > 0 Then
stmp = "sko" & Format(i)
strSQL = strSQL & ", " & stmp & "=" & .ShoeNr(i)
tmp = tmp - 1
Else
stmp = "sko" & Format(i)
strSQL = strSQL & ", " & stmp & "=" & 0
End If
Next
strSQL = strSQL & " WHERE ordernr=" & .QueNr & ";"
Else
strSQL = "INSERT INTO orders VALUES(" _
& .QueNr & ", " _
& "'" & .PersNr & "', " _
& "'" & .Phone & "', " _
& "'" & .Adress & "', " _
& "'" & .Comment & "', " _
& "'" & .Datum & "', " _
& .Antal
For i = 1 To 10
If tmp > 0 Then
strSQL = strSQL & ", " & .ShoeNr(i)
tmp = tmp - 1
Else
strSQL = strSQL & ", " & 0
End If
Next
strSQL = strSQL & ", " & 0 & ");"
End If
End With
conn.Execute strSQL, , adExecuteNoRecords
hth /Henning
>> Stay informed about: Using variables to write data to an Access file