SQL Help!!!
Megadeth4168
Member Posts: 2,157
in Off-Topic
This is a snippet of Code from my Access Project. I am trying to get me Variable to work for strFieldName.
Before I had everythign as is except I decided to change strSQL from
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.
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
-
Megadeth4168 Member Posts: 2,157Problem solved....
Apparently the single quotes in the strSQL statement should not be placed around my first variable but should be placed around my other 2. I'm not sure I understand why but it works now.