ACCESS2000 and VBA variable usage - TechRepublic
General discussion
April 2, 2001 at 02:40 AM
mike52

ACCESS2000 and VBA variable usage

by mike52 . Updated 25 years, 1 month ago

Function getit() As Variant
Dim myrs1 As DAO.Recordset
Dim myrs2 As DAO.Recordset
Dim mydb As DAO.Database
Set mydb = CurrentDb
Set myrs1 = mydb.OpenRecordset(“query5”)
Set myrs2 = mydb.OpenRecordset(“query4″)
Dim infstr As Variant
Dim fldname(8) As String
fldname(1)=”field1″
fldname(2)=”field2″
myrs2.AddNew
infstr = ” ”
infstr = myrs1![combine]
myrs2![toutxx] = infstr
myrs2.Update
End Function

This is a sample of my code. What I want to be able to do is place the ‘addnew’ to’update’ portion into a loop that will handle up to 9 fields defined in an array. By then changing the value of the logstr I should be able to update variable fields.
When I set the statement myrs2!fldname(1)=textstr, I get an error stating that field name is not part of that recordset. In debug mode it shows that the array contains the proper field name. There must be something in the statement that will not allow the use of the variable and I can only use actual field names from the query within brackets. I have tried putting quotes and/or brackets around the array name to no avail.
If you have any ideas you can reply here or e-mail me at michaeldj_52@hotmail.com.

This discussion is locked

All Comments