By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,284 Members | 1,564 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,284 IT Pros & Developers. It's quick & easy.

How do I create a record in a table using information in form controls?

Seth Schrock
Expert 2.5K+
P: 2,951
I'm creating a billing database and currently, I'm pulling records from the sales table using the current CustomerID, and two textboxes to give a date range as the criteria for the query. From here, I want to be able to create a record in the Invoices table with the CustomerID, StartDate, and EndDate from the form. The Invoices table is designed as follows:
Expand|Select|Wrap|Line Numbers
  1. tblInvoices
  2. InvoiceID   PK
  3. CustomerID
  4. BeginDate
  5. EndDate
At first I thought I would use an Append Query, but it looks like the information has to be from a datasource such as another table or SQL database. I could use an Update Query if I could have it update the new record since the InvoiceID is an AutoNumber field. What is the best way do to this?
Nov 9 '11 #1
Share this Question
Share on Google+
1 Reply

Seth Schrock
Expert 2.5K+
P: 2,951
I found a method using VBA. The code is the following:
Expand|Select|Wrap|Line Numbers
  1. Dim dbBilling As DAO.Database
  2.     Dim rstInvoices As DAO.Recordset
  4.     Set dbBilling = CurrentDb
  5.     Set rstInvoices = dbBilling.OpenRecordset("tblInvoices")
  7.     rstInvoices.AddNew
  8.     rstInvoices("CustomerID").Value = Forms!frmCustomer!CustomerID
  9.     rstInvoices("BeginDate").Value = Forms!frmCustomer!txtStartDate
  10.     rstInvoices("EndDate").Value = Forms!frmCustomer!txtEndDate
  11.     rstInvoices.Update
Nov 10 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.