Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using THISFORM in UPDATE query to SET the field value

Status
Not open for further replies.

mdav2

Programmer
Aug 22, 2000
363
GB
I want to use an SQL update statement that looks like this (i've not included a where clause but usually would):

Code:
UPDATE table1 SET cfirstname = thisform.txtfirstname.value

This returns an error:

ALIAS "txtfirstname" is not found

Now if I create this as a string and run it using this code it will work.

Code:
csql = "UPDATE table1 SET cfirstname ='" + thisform.txtfirstname.value + "'"
&csql

Now I understand the statement that errors contains text and so should be qualified by quotes but adding them to original statement makes no difference.

I was wondering if there is anyway to do these sorts of queries without building a string?

Thanks,

Mark

Mark Davies
Warwickshire County Council
 
Yes, just assign all values to variables:
Code:
lcFirstName = thisform.txtfirstname.value
UPDATE table1 SET cfirstname = m.lcFirstName

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
The first update should work in the context of thisform, eg in a click event of a button of that form.

Why the second statement needs string delimiters? Take a look at cSQL: ? cSQL, then you'll see, it's more like
UPDATE table1 SET cfirstname = 'Mark', not UPDATE table1 SET cfirstname = 'thisform.txtfirstname.value'. See now?

As a suolution: Borislav's suggestion is what I'd suggest too. Has a big advantage, if you eg enter the name O'Brian. See why?

Bye, Olaf.
 
Thanks for the posts, I use both solutions in different languages. I am just glad I am not going mad thinking it must be possible. Putting them in variables is useful for getting rid of those annoying Irish names (from a coding point of view). I'll remember that for the future.

Mark Davies
Warwickshire County Council
 
Don't forget that you can use [ and ] as string delimiters too:
Code:
Messagebox([Cannot find a name like "] + thisform.txtfirstname.value + ["])

This will display correctly even with names which include an apostrophe:

Cannot find a name like "O'Brian"

Geoff Franklin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top