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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add record to table from form 2

Status
Not open for further replies.

haytatreides

IS-IT--Management
Oct 14, 2003
94
US
I have a form that lists two tables, and pulls data from a third. What i want to do is this, i want to add a record to the third table, inputing variables from my form into the fields. i just need to know how to add the data to the fields. any help would be appreciated!

hayt
 
How about:

currentdb.execute "insert into tablename (field1, field2, ...) values (value1, value2, ...)



-Coco

[auto]
 
Lemme try that, i didnt know the currentdb.execute command. you rock, even if i dont use it, i know i will before this project is through!!!!

hayt
 
what i have is
docmd.opentable "MyTable", acNormalView
DoCmd.GoToRecord , , acNewRec
Field1 = Variable1
Field2 = Variable2
.
.
.
DoCmd.Close acTable, "MyTable", acSaveYes

It is the field = variable part that i dont know how to do.

hayt
 
I would create a recordset of the third table and use that to add your data. Make sure you Declare all of your variables and fields. Hope this is what you are after.

'Create recordset
Set mrs = db.OpenRecordset("SELECT fields FROM table , dbOpenDynaset)
'Edit RS
mrs.Edit
Field1 = Variable1
'Update fields with new values
mrs.Update
mrs.Close
Set db = Nothing

Dave
 
what is the set db = nothing? and under the set recordset, do i need to put a select statement there? (sorry, i come from a c++ background, so i am having some difficulty. i don't mean to be an idiot!)

hayt
 
i got it! i have no idea why it didnt work before, but i opened the recordset as openstatic, lockoptimistic and cmdtabledirect, and that worked. no idea why!

hayt

thanks everyone!
 
Sorry I didn't get right back with you. Missed setting the db = CurrentDb().

Glad you figured it out though.

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top