473,503 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Procedure to insert new text from combo box into a table

22 New Member
Hi, I have an "Add New Records To Table" form. In the header of the form there is a combo box (artistsource) which looks up values from a different table (Artist), the value selected by the user is set as the default value for one of the fields on the records. The user isn't restricted to the data in the artist table and may type in a new artist. What I am trying to code is that when the user closes the form, if the user typed in a new artist into the combo box it is added to the artist table so it will be there and can be selected next time. I have written a SQL procedure for this which technically works, although it has some problems:

Expand|Select|Wrap|Line Numbers
  1. Sub TableUpdate()
  2.  
  3.     If ArtistSource <> "" Then
  4.         DoCmd.RunSQL ("Insert into Artist (Artist) values ([artistsource])")
  5.     Else
  6.         MsgBox "You haven't selected an artist from the list or typed in a new one"
  7.     End If
  8.  
  9. End Sub
  10.  
The main problem is that I wanted the procedure to first search the Artist table with the value from the artistsource combo box. If the search couldn't find a match then that must mean the user typed in a new artist. As a result of this the SQL code would run and add the new artist to the table. I couldn't work out how to write the searching procedure, so i just worked out the adding part. Do you have any hints/ideas on how to write the searching procedure? I would have used the findrecord method but the table to be searched is not referenced in the form.

The second problem (more an aesthetic one than a code one) is that when running the SQL code a big warning pops up saying: "You are about to append 1 row(s)". I do not want this warning because I know what it is about to do. Is there anyway of bypassing it?
Jan 8 '08 #1
2 2923
Minion
108 Recognized Expert New Member
Hi, I have an "Add New Records To Table" form. In the header of the form there is a combo box (artistsource) which looks up values from a different table (Artist), the value selected by the user is set as the default value for one of the fields on the records. The user isn't restricted to the data in the artist table and may type in a new artist. What I am trying to code is that when the user closes the form, if the user typed in a new artist into the combo box it is added to the artist table so it will be there and can be selected next time. I have written a SQL procedure for this which technically works, although it has some problems:

Expand|Select|Wrap|Line Numbers
  1. Sub TableUpdate()
  2.  
  3.     If ArtistSource <> "" Then
  4.         DoCmd.RunSQL ("Insert into Artist (Artist) values ([artistsource])")
  5.     Else
  6.         MsgBox "You haven't selected an artist from the list or typed in a new one"
  7.     End If
  8.  
  9. End Sub
  10.  
The main problem is that I wanted the procedure to first search the Artist table with the value from the artistsource combo box. If the search couldn't find a match then that must mean the user typed in a new artist. As a result of this the SQL code would run and add the new artist to the table. I couldn't work out how to write the searching procedure, so i just worked out the adding part. Do you have any hints/ideas on how to write the searching procedure? I would have used the findrecord method but the table to be searched is not referenced in the form.

The second problem (more an aesthetic one than a code one) is that when running the SQL code a big warning pops up saying: "You are about to append 1 row(s)". I do not want this warning because I know what it is about to do. Is there anyway of bypassing it?

If I'm reading this correctly you're making the first part a lot harder than it really need to be. You should be able to set the combo box to retreive it's values from the artists table, but save the selected value to a field in your other table. Once this is set (easily done through the wizard for combo boxes) go into the properties for the combo box (select it and press alt+enter) and under the data tab set "Limit To List" to "NO". This should allow the user to type in a new value and it will save it to the field in your second table. However, if you want that to be added to your first table you'll need to append it (there's a not in list event for this).

As for your second question about the pop up you can disable that by using the following code before you execute the SQL.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.SetWarnings = False
  2.  
Hope this helps.

- Minion -
Jan 8 '08 #2
shredder249
22 New Member
Cheers =) all working out now

If I'm reading this correctly you're making the first part a lot harder than it really need to be. You should be able to set the combo box to retreive it's values from the artists table, but save the selected value to a field in your other table. Once this is set (easily done through the wizard for combo boxes) go into the properties for the combo box (select it and press alt+enter) and under the data tab set "Limit To List" to "NO". This should allow the user to type in a new value and it will save it to the field in your second table. However, if you want that to be added to your first table you'll need to append it (there's a not in list event for this).

As for your second question about the pop up you can disable that by using the following code before you execute the SQL.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.SetWarnings = False
  2.  
Hope this helps.

- Minion -
Jan 10 '08 #3

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

Similar topics

2
2681
by: Uninvisible | last post by:
I have put together a db for a law firm to keep track of counterfeit activities. There are four parent tables: tblContact tblTransaction tblAction tblFile I have created a form,...
9
5262
by: joun | last post by:
Hi all, i'm using this code to insert records into an Access table from asp.net, using a stored procedure, called qry_InsertData: PARAMETERS Long, Long, Text(20), Long, DateTime; INSERT...
1
1514
by: Yoshitha | last post by:
Hi i've created one table and one stroed procedure to insert data into that table. i've created table like this table Name=QA_QAuthor EmailId Varchar primarykey. Pwd ...
22
4249
by: M K | last post by:
Heres my SP: ( i am trying to add more than 1 field but get the same error no matter how many i try to add, i thought i would try to insert the primary key only and work up from there but the...
6
2337
by: SandySears | last post by:
I am trying to use a stored procedure to insert a record using VS 2005, VB and SQL Server Express. The code runs without errors or exceptions, and returns the new identifer in the output...
6
2598
by: rn5a | last post by:
In a shopping cart app, when a user finalizes his order, records from a temporary table named 'TempCart' get inserted into another table name 'Orders' after which the records from 'TempCart' are...
9
2674
by: serge | last post by:
/* Subject: How to build a procedure that returns different numbers of columns as a result based on a parameter. You can copy/paste this whole post in SQL Query Analyzer or Management Studio...
2
4787
by: technocraze | last post by:
Hi guys, I have encountered this error when updating the values to the MS Acess table. Error : Update on linked table failed. ODBC sql server error Timeout expired. MS Acess is my front end and...
0
1907
by: ramuygl | last post by:
want to create store procedure that. want to send the table name as argument and retrive the data of that argument. and want to store data in temperary table using the insert query. HERE I AM...
0
7203
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
7089
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
7282
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,...
1
6995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.