Recently I created some code that used DAO to read table/field information contained in a table I'd constructed for that purpose in order to append a number of new fields to their respective tables elsewhere in the database.
For example the source table for the table/field information works something like this...
[pre]TableNm TableFld FldType FldSize[/pre]
[pre]------- -------- ------- -------[/pre]
[pre]tItem Color dbText 50[/pre]
[pre]tItem Quantity dbLong 4[/pre]
The code then loops though the records in this table and loads them into variables.
[pre]Dim strTblNm As String 'aka TableNm[/pre]
[pre]Dim strFldNm As String 'aka TableFld[/pre]
[pre]Dim strFldType As String 'aka FldType[/pre]
[pre]Dim lngSize As Long 'aka FldSize[/pre]
My original idea was to then feed these values to the statement
tdf.Fields.Append tdf.CreateField(strFldNm, strFldType, lngSize)
but the problem I ran into is that resulting statement became...
tdf.Fields.Append tdf.CreateField("Color", "dbText", 50)
while what I needed was...
tdf.Fields.Append tdf.CreateField("Color", dbText, 50)
(no quotes around dbText)
I was able to work around the problem by changing the FldType to a long integer and substituting the integer value for each DAO Field Type (e.g. dbTexT = 10) and the code now runs pefectly. But my question is if there is any way that I could have gotten the original idea to work (pass dbText to the statement without the quotes) by dimensioning the variable differently or some other means?
For example the source table for the table/field information works something like this...
[pre]TableNm TableFld FldType FldSize[/pre]
[pre]------- -------- ------- -------[/pre]
[pre]tItem Color dbText 50[/pre]
[pre]tItem Quantity dbLong 4[/pre]
The code then loops though the records in this table and loads them into variables.
[pre]Dim strTblNm As String 'aka TableNm[/pre]
[pre]Dim strFldNm As String 'aka TableFld[/pre]
[pre]Dim strFldType As String 'aka FldType[/pre]
[pre]Dim lngSize As Long 'aka FldSize[/pre]
My original idea was to then feed these values to the statement
tdf.Fields.Append tdf.CreateField(strFldNm, strFldType, lngSize)
but the problem I ran into is that resulting statement became...
tdf.Fields.Append tdf.CreateField("Color", "dbText", 50)
while what I needed was...
tdf.Fields.Append tdf.CreateField("Color", dbText, 50)
(no quotes around dbText)
I was able to work around the problem by changing the FldType to a long integer and substituting the integer value for each DAO Field Type (e.g. dbTexT = 10) and the code now runs pefectly. But my question is if there is any way that I could have gotten the original idea to work (pass dbText to the statement without the quotes) by dimensioning the variable differently or some other means?