473,388 Members | 1,340 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

How to Use results of text and combo boxes for new record in table

I am working in Access 2007.
I have a form named Master Terms List that contains 4 bound text boxes and 7 cascading combo boxes. The bound text boxes have data sources from a table named Termslist. The record source for the 7 cascading combo boxes is also the table Termslist.
The names of the fields on form Master Terms List and the type of controls they are follows:
Termslistmonth - text box
DateReceived - text box
Coordinator - combo box
Customers - combo box
Vendor - combo box
shared - combo box
DBA - combo box
Brand - combo box
Grpnbr - combo box
vastart - text box
vaend - text box
When a new record is generated, the user enters the terms list month, date received, selects coordinator name from a dropdown list, selects customer, vendor, shared vendor, DBA(doing business as), brand name, group number, start date and end date. The cascading combo boxes work fine and are all synchronized.
I need to use the results of these selections as the base data for a new record that will be saved to a temporary table named temptermslist. I have attempted to write some code that defines the fields to be appended to the temptermslist table using the results in the form Master Terms List.
I have the code linked to a button named Savenewva. I am not really proficient in VB but have managed in the past to find enough code on help boards etc to get the job done.
The code is below.

Option Explicit

Private Sub BtnSaveNewVA_Click()

Insert Into(Temptermslist(TermsListMonth, DateVendorAgreementReceived, CoordinatorName, CustomerName, VendorName, SharedVdr, DBA, BrandNames, PRIMEShareGroupnbr, VAStartDate, VAEndDate))
"SELECT (TermsListMonth,DateVendorAgreementReceived,Coordi natorName,CustomerName,VendorName,SharedVdr,DBA,Br andNames,PRIMEShareGroupnbr,VAStartDate,VAEndDate) FROM" & _
"Forms![Master Terms List] WHERE (((TermsListMonth)=[forms]![Master Terms List].[txttermslistmonth]) AND ((DateVendorAgreementReceived)=[forms]![Master Terms List].[txtdatereceived]) AND ((CoordinatorName)=[forms]![Master Terms List].[cbocoordinator])AND ((CustomerName)=[forms]![Master Terms List].[cbocustomers]) AND ((VendorName)=[forms]![Master Terms List].[cbovendor]) AND ((SharedVdr)=[forms]![Master Terms List].[cboshared]) AND ((DBA)=[forms]![Master Terms List].[cbodba]) AND ((BrandNames)=[forms]![Master Terms List].[cbobrand]) AND ((PRIMEShareGroupnbr)=[forms]![Master Terms List].[cbogrpnbr]) AND ((VAStartDate)=[forms]![Master Terms List].[txtvastart]) AND ((VAEndDate)=[forms]![Master Terms List].[txtvaend]))"

End Sub

The code fails on the first line at the word temptermslist. The error message from access is "compile error: sub or function not defined".
I have tried to figure out what this means but am stuck and have been researching this issue for about 1 week. Any help would be appreciated.
Sep 16 '10 #1
3 1495
ChipR
1,287 Expert 1GB
Here is an example so you can see the syntax. You want to build a string with the values from your form, then run it. This example takes the values from txtBoxes.

Expand|Select|Wrap|Line Numbers
  1.     Dim strSQL As String
  2.  
  3.     strSQL = "INSERT INTO MyTable VALUES (" & txtNumber _
  4.            & ", " & txtAnotherNumber & ", """ & txtString _
  5.            & """, """ & txtAnotherString & """)"
  6.  
  7.     'MsgBox strSQL  'so you can see that it is right
  8.  
  9.     DoCmd.SetWarnings False
  10.     DoCmd.RunSQL strSQL, 0
  11.     DoCmd.SetWarnings True
Sep 17 '10 #2
Chip,
Thanks for your help. The code I have written is below. I am getting a "compile error Variable not defined and strSql on the insert into line of code is highlighted. I'm not exactly sure how to define the variable. Any additional help would be appreciated.

Option Compare Database
Option Explicit


Private Sub BtnSaveNewVA_Click()

Dim strSQL As String

srtSQL = "Insert Into Temptermslist Values (" & txtTermsListMonth & "," & txtDateReceived & "," & cboCoordinator & "," & cbocustomers & "," & cboVendor & "," & cboShared & "," & cboDBA & "," & cboBrand & "," & cbogrpnbr & "," & txtvastart & "," & txtvaend & """)"

MsgBox strSQL("I hope this is right")
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL, 0
DoCmd.SetWarnings True


End Sub
Sep 17 '10 #3
ChipR
1,287 Expert 1GB
Your declaration of the strSQL variable is fine, but you seem to have a typo at
Expand|Select|Wrap|Line Numbers
  1. srtSQL = ... 
I don't think that MsgBox line will compile (when you get there). Just take out the part in the parenthesis for now.

For building your string, you will need to match up the quotation marks. Take a look at this post which will explain everything:
Quotes (') and Double-Quotes (") - Where and When to use them

We'll be happy to help if you still have issues afterward.
Sep 17 '10 #4

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

Similar topics

1
by: Paolo | last post by:
I would like some help on the use of combo boxes. I have created a form and named it Customers. This form's record source is a table, also named Customer. I would now like to add an unbound combo...
1
by: James | last post by:
I am used to VB6 but need to develop something in .Net. I need to create several bound combo-boxes which will use lookup tables to get their values. I created a form using the dataform wizard....
9
by: Edwinah63 | last post by:
Hi everyone, Please let there be someone out there who can help. I have two BOUND combo boxes on a continuous form, the second being dependent on the first. I have no problem getting the...
6
by: GaryGreenberg | last post by:
I am developing a web page for order processing using Spring MVC. In my JSP I have a table populated from the list of orders that are passed in the model (form backing object). Some fields there are...
1
by: Chrish1987 | last post by:
Dear All, I have the following Tables: Dealer: DealerID - AutoNumber DealerName - Text Business: Business ID - AutoNumber
6
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
1
by: Dave | last post by:
Hello all, First I'd like to apologize...This post was meant to be put in my previous post, but I tried many times without success to reply within my previous post. Now here goes... I have a...
4
by: deanndra | last post by:
First, I want to say thank you to Scott and the others who replied to my first post here. I had to put that database on hold for the moment when I was tasked with a new one. I am building another...
2
by: PiCubed | last post by:
I'm trying to create a form that uses combo boxes to select a table and then from that table I need to create linked combo boxes that searches for information. The first combo selects the table the...
8
doma23
by: doma23 | last post by:
I have 5 combo boxes which represent certain periods. The row source of these 5 combo boxes is table tblRefDate. What I want to do is to make a procedure that when period is inserted in any of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.