SQL Help!!!

Megadeth4168Megadeth4168 Member Posts: 2,157
This is a snippet of Code from my Access Project. I am trying to get me Variable to work for strFieldName.
strFieldName = "[Last Name]"
strLastName = Me![Last Name]
 strInput = InputBox("Which Lot will you move data to?", "Lot Transfer", , 5000, 5000)

strSQL = "UPDATE Lot SET '" & strFieldName & "' = '" & strLastName & "' WHERE [Lot Number]= '" & strInput & "';"
    DoCmd.SetWarnings False
    DoCmd.RunSQL strSQL
    DoCmd.SetWarnings True

Before I had everythign as is except I decided to change strSQL from
strSQL = "UPDATE Lot SET [Last Name]
to
strSQL = "UPDATE Lot SET '" & strFieldName & "'

Everything was working perfectly before I did that.
The whole reason I wanted to make that part of the Statement a variable was because I have several fields that I would like to move all at once to another record and I was just going to make a simple loop that will change the variable string based on the count number.

I have tried the following:
strFieldName="[Last Name]"
Which gives me a Invalid use of Brackets
strFieldName=[Last Name]
Which makes teh statement thing the field name is actually the data in the field.
strFieldName="Last Name"
Which prompts me to enter parameter for 'Last Name'

If I can't figure this out I have an alternate method but it will look messy and take ffar more code.

Thanks for any help anyone can provide.

Comments

Sign In or Register to comment.