Writing Data To Table

J

J

Just wondering how I would write data to a table on a button click
after i have entered the data into a form. All help appreciated.
 
G

Guest

Hi,
you could just make the form bound and then when the record loses focus it
will save the data to the appropriate fields. If this is unbound you could
use code like this:

Dim rs As New ADODB.Recordset
Dim varItem As Variant

rs.Open "tblYourTable", CurrentProject.Connection, adOpenDynamic,
adLockOptimistic

rs.AddNew
rs!Field01 = Me.YourControl01
rs!Field02 = Me.YourControl02
rs.Update

rs.Close
Set rs = Nothing

HTH
Good luck
 
G

Guest

If you don't want to deal with VBA, you could use a Macro to run a Query.
Create an Append Query based on your table. Choose your table as the Append
Table or target table. In the Criteria portion of the Query, you will put
the controlnames as the condition. Exp:

[Forms]![YourFormsName]![YourTxtBox]

Then on the click event, choose Macro. On the Action pull down, select
OpenQuery. In the Action Arguments Box at the bottom, select your Query
Name, and Data mode. Save your Macro and exit.

When you click the button, it should run the Append Query, and update your
table. Macros are easy to use for certain situations. Once you become more
familiar with VBA, it allow you greater flexibility to modify actions on the
fly. Good Luck!
 
J

J

I'm still having some problems. I set up the macro to run the query but
apparently it's saying "You are about to append 0 Rows" Some data that
I have is:

Field: Quantity
Table: Inventory Table
Sort:
Append To: Quantity
Criteria: [Forms]![Inventory Entry Screen]![Quantity]
Or
 
G

Guest

Okay, I know what I told you wrong now. Instead of filling out the criteria
portion of the query, we'll just put it right into the field. In the field
write:

Field: Quantity: [forms]![Inventory Entry Screen]![Quantity]

Do this for all the controls you want to populate in your table.

Leave the Table: blank and the Criteria: blank and it should work now. Let
me know if it doesn't. Good luck.
 

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