I
IM
I don't know if this has come up before. I'd like to dynamically create a
line of VBA code at run time based on values from a table, or a textbox. I
want to use this code to get data from a recordset. The code would vary
depending upon another table which specifies the field name and data type.
Is there a way to do this? Below is a sample code fragment. Clearly, I can
use this approach to build a text string that is displayable in a msgbox,
but can't build the same string as an executable line of code... or can I?
===Begin code fragment======================================================
Private Sub Command8_Click()
Dim strSrcTbl, strTargTbl, strSrcFld, strTargFld, strFldType, strAction As
String
strSrcTbl = Me.SourceTable
strSrcFld = Me.SourceField
strTargTbl = Me.TargetTable
strTargFld = Me.TargetField
strAction = Me.Action
strFldType = Me.FieldType
'Buffers to hold different data types
Dim stringBuff As String
Dim doubleBuff As Double
Dim dateBuff As Date
'Define RecordSets
Dim Db As DAO.Database
Dim rsBrioFeed, rsProgram, rsImportActions As DAO.Recordset
Set Db = CurrentDb()
Set rsBrioFeed = Db.OpenRecordset("BrioFeed", dbOpenTable)
Set rsProgram = Db.OpenRecordset("tblProgram", dbOpenTable)
Set rsImportActions = Db.OpenRecordset("tblImportActions", dbOpenTable)
'I want the next statement (surrounded by asterisks) to build dynamically
based on the values in _
strFldType and strSrcFld so that code is generated like: _
stringBuff=rsBrioFeed.Name or _
dateBuff =rsBrioFeed.StartDate
'*************************************************
'strFldType & "Buff" & "=rsBrioFeed." & strSrcFld 'this won't even compile
'*************************************************
'as in the following message box, which works just fine as a string
MsgBox strFldType & "Buff" & "=rsBrioFeed." & strSrcFld
'OTHER CODE...
===End code fragment======================================================
Am I going bonkers, or is this possible?
Thanks for any help.
IzM
line of VBA code at run time based on values from a table, or a textbox. I
want to use this code to get data from a recordset. The code would vary
depending upon another table which specifies the field name and data type.
Is there a way to do this? Below is a sample code fragment. Clearly, I can
use this approach to build a text string that is displayable in a msgbox,
but can't build the same string as an executable line of code... or can I?
===Begin code fragment======================================================
Private Sub Command8_Click()
Dim strSrcTbl, strTargTbl, strSrcFld, strTargFld, strFldType, strAction As
String
strSrcTbl = Me.SourceTable
strSrcFld = Me.SourceField
strTargTbl = Me.TargetTable
strTargFld = Me.TargetField
strAction = Me.Action
strFldType = Me.FieldType
'Buffers to hold different data types
Dim stringBuff As String
Dim doubleBuff As Double
Dim dateBuff As Date
'Define RecordSets
Dim Db As DAO.Database
Dim rsBrioFeed, rsProgram, rsImportActions As DAO.Recordset
Set Db = CurrentDb()
Set rsBrioFeed = Db.OpenRecordset("BrioFeed", dbOpenTable)
Set rsProgram = Db.OpenRecordset("tblProgram", dbOpenTable)
Set rsImportActions = Db.OpenRecordset("tblImportActions", dbOpenTable)
'I want the next statement (surrounded by asterisks) to build dynamically
based on the values in _
strFldType and strSrcFld so that code is generated like: _
stringBuff=rsBrioFeed.Name or _
dateBuff =rsBrioFeed.StartDate
'*************************************************
'strFldType & "Buff" & "=rsBrioFeed." & strSrcFld 'this won't even compile
'*************************************************
'as in the following message box, which works just fine as a string
MsgBox strFldType & "Buff" & "=rsBrioFeed." & strSrcFld
'OTHER CODE...
===End code fragment======================================================
Am I going bonkers, or is this possible?
Thanks for any help.
IzM