Hi guys
I am writing the following code that will create new fields in the table when command button is clicked. and will update those fields with some data. But suppose once the field loc(0) is created then the next time loc(1) should be created but it gives the error
"Field loc(0) already exist in the table"
I think there is some problem with static variable that I have declared.
I am writing the following code that will create new fields in the table when command button is clicked. and will update those fields with some data. But suppose once the field loc(0) is created then the next time loc(1) should be created but it gives the error
"Field loc(0) already exist in the table"
I think there is some problem with static variable that I have declared.
Code:
Private Sub Command20_Click()
Static aa As Integer
s1 = "ALTER TABLE rebookinfo ADD [loc(" & aa & ")] varchar(20),[Dept(" & aa & ")] varchar(20);"
DoCmd.SetWarnings False
DoCmd.RunSQL s1
sSQL = "Update rebookinfo set [loc(" & aa & ")] = '" & Me.[Combo33].Value & "' , [Dept(" & aa & ")]= '" & Me.[Combo35].Value & "' where Barcodevalue = '" & Text25.Value & "'"
DoCmd.SetWarnings False
DoCmd.RunSQL sSQL
aa = aa + 1
end sub