PDA

Click to See Complete Forum and Search --> : Insert into statement


turfbult
Aug 2nd, 2000, 01:52 PM
Hi,

I want to do something very simple, but cannot get it working.

I have an MS Access database "Contacs", Table "Friends" with fields "Name" and "surname" and a form with textboxes "txtname" and "txtsurname" and an update command button.

All I want to do is add names and surnames entered into the textboxes into the table (friends) when the user click the update button ie.

insert into friends values (txtname.text,txtsurname.text).

Why does this not work???? It works fine when I hardcode the fields ie.
insert into friends values ("Dan","Abercrombie").

JHausmann
Aug 2nd, 2000, 02:43 PM
Your variables need to be wrapped in quotes, Give this a shot:

sSQL = "insert into friends values ('" & txtname.text & "','" & txtsurname.text & "')"

turfbult
Aug 2nd, 2000, 02:49 PM
Thank you very much!!! You wont believe this, but I could not find any help in any of my books (teach yourself by Sams) on this problem I had.

xstopx81
Aug 2nd, 2000, 03:03 PM
Can you explain your problems more specifically? does your program have database object in the form? Maybe the problem your having is due to the unlinked text boxes. For your text boxes properties, you might want to declare datasource and datamember. then for command click botton, just write:
datMydatabasename.recordset.addnew
if you have more problems, email me at xstopx81@hotmail.com