Hi everyone, Im new to the forum and I have a question I cannot find an answer to.
I need to loop through fields to add header names. Every time I run the code I get an invalid operation error. So, is there a way I can loop through the fields. I do not want to have to copy and paste the code a ton of times to get this to be dynamic. I will post code.
Thanks!
While looper < 100
custName = rs("NAM")
custInfo(looper, 0) = custName
custInfo(looper, 1) = looper
Set fld(looper) = tbl.CreateField(custName, dbText) 'Where I get the error
fld(looper).AllowZeroLength = True
tbl.Fields.Append fld(looper)
looper = looper + 1
Set fld(looper) = tbl.CreateField(custName & " Units", dbText)
fld(looper).AllowZeroLength = True
tbl.Fields.Append fld(looper)
looper = looper + 1
Set fld(looper) = tbl.CreateField(custName & " Invoice Date", dbText)
fld(looper).AllowZeroLength = True
tbl.Fields.Append fld(looper)
looper = looper + 1
If rs.EOF Then
looper = 100
End If
Wend
I need to loop through fields to add header names. Every time I run the code I get an invalid operation error. So, is there a way I can loop through the fields. I do not want to have to copy and paste the code a ton of times to get this to be dynamic. I will post code.
Thanks!
While looper < 100
custName = rs("NAM")
custInfo(looper, 0) = custName
custInfo(looper, 1) = looper
Set fld(looper) = tbl.CreateField(custName, dbText) 'Where I get the error
fld(looper).AllowZeroLength = True
tbl.Fields.Append fld(looper)
looper = looper + 1
Set fld(looper) = tbl.CreateField(custName & " Units", dbText)
fld(looper).AllowZeroLength = True
tbl.Fields.Append fld(looper)
looper = looper + 1
Set fld(looper) = tbl.CreateField(custName & " Invoice Date", dbText)
fld(looper).AllowZeroLength = True
tbl.Fields.Append fld(looper)
looper = looper + 1
If rs.EOF Then
looper = 100
End If
Wend
Last edited: