how to add data inseted on a form into a database

G

Guest

I have created a form with these 5 fields Txtdate, txtname, txtaddress,
txtphone and txtfax. When I enter these fields I want to save it back to the
table i've created called members which have the same names as the field
names on the form. This is what I have done so far
option explicit
dim rst as recordset
dim db as database
dim count as integer

in the save command i have

Private sub cmdsave_click()
set db = current db
if xcount = o then
set rst = db.openrecordset("select * from members")
with rst
..addnew
!txtdate = txtdate
!txtname = txtname
!txtaddress = txtaddress
!txtphone = txtphone
!txtfax = txtfax
..update
end with
rst.close
db.close
end sub

unknown to me this doesn't work. Please help?
 
D

Duane Hookom

Did you try to compile? Do you know you can copy and paste your exact code
into a message? When you say "this doesn't work" you are short changing us
by not providing a more descriptive symptom.

current db
should be
CurrentDb

dim rst as recordset
dim db as database
should be
Dim rst As DAO.Recordset
Dim db As DAO.Database

You have dim'd xcount and I expect
if xcount = o then
should be
If xcount = 0 Then
What are you doing with xcount or count? If you dim an integer memory
variable, you should name the variable intCount or similar.

I would probably execute an INSERT SQL statement rather than opening a
recordset but that is up to you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top