AKMonkeyboy
IS-IT--Management
I found some great code for adding a Yes/No field to a table, but need some help modifying the code to allow for a loop/dowhile. I have alot of fields to add and don't want to have to type it all in. This is the code without the loop (I know how to do that), but with my modifications allowing for variable field names (all my field names are the same except for the last character which will increase by 1 each time).
Every time I run the code I get a message:
Compile error: Object required.
I'm being told the problem is the line that reads:
Set tjFld = strFieldUpdate
Any thoughts on what I might be doing wrong?
Thanks,
Adam
Give a man a fish, and you feed him for a day.
Teach a man to fish, and you feed
him for life.
Send a man to Tek-Tips and the poor sap can find out how to fish on his own, and learn more by doing it.
Code:
Private Sub btn18_Click()
Dim intField As Integer
Dim strFieldUpdate As String
Dim strFieldAdd As String
intField = 1
strFieldAdd = "ALTER TABLE tblPhysicianMod ADD COLUMN fraStatement1a" & intField & " YesNo;"
strFieldUpdate = "tjTab.Fields!fraStatement1a" & intField
'Add Delete Column to tblLabs
Set tjDb = CurrentDb
Set tjTab = tjDb.TableDefs!tblPhysicianMod
tjDb.Execute strFieldAdd
Set tjFld = strFieldUpdate
Set tjPropFormat = tjFld.CreateProperty("Format", dbText, "Yes/No")
tjFld.Properties.Append tjPropFormat
Set tjPropDisplay = tjFld.CreateProperty("DisplayControl", dbInteger, acCheckBox)
tjFld.Properties.Append tjPropDisplay
tjDb.Close
Set tjPropDisplay = Nothing
Set tjPropFormat = Nothing
Set tjFld = Nothing
Set tjTab = Nothing
Set tjDb = Nothing
End Sub
Every time I run the code I get a message:
Compile error: Object required.
I'm being told the problem is the line that reads:
Set tjFld = strFieldUpdate
Any thoughts on what I might be doing wrong?
Thanks,
Adam
Give a man a fish, and you feed him for a day.
Teach a man to fish, and you feed
him for life.
Send a man to Tek-Tips and the poor sap can find out how to fish on his own, and learn more by doing it.