Dynamic ADO Field Names

  • Thread starter Thread starter MF Scheetz
  • Start date Start date
M

MF Scheetz

I was wondering if there was a way to use an if statement to change an ado
field name that is to be updated similar to the following:

Dim FieldNm as String
Dim cn as ADODB.Connection
Dim rsTable as ADOBD.Recordset

Set cn = Currentproject.connection
set rsTable = new adodb.recordset

rsTable.Open "SELECT * FROM TableName",cn, adOpenDynamic, adLockOptimistic

IF Variable = True Then
FieldNm = Field1
ELSEIF Variable = False then
FieldNm = Field2
endif
rsTable.addnew
rsTable.fields('"& FieldNm &"') = 2
rsTable.update

rsTable.close
cn.close

Any help is greatly appreciated.
 
What are Field1 and Field2? If they're supposed to be the names of the
fields, you're missing quotes around them:


IF Variable = True Then
FieldNm = "Field1"
ELSEIF Variable = False then
FieldNm = "Field2"
endif
 
Yeah they are field names. But I ended going about this problem a completely
different way. But thanks for the help!
 
Back
Top