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: -
Sub TableUpdate()
-
-
If ArtistSource <> "" Then
-
DoCmd.RunSQL ("Insert into Artist (Artist) values ([artistsource])")
-
Else
-
MsgBox "You haven't selected an artist from the list or typed in a new one"
-
End If
-
-
End Sub
-
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?
2 2934 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: -
Sub TableUpdate()
-
-
If ArtistSource <> "" Then
-
DoCmd.RunSQL ("Insert into Artist (Artist) values ([artistsource])")
-
Else
-
MsgBox "You haven't selected an artist from the list or typed in a new one"
-
End If
-
-
End Sub
-
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. -
DoCmd.SetWarnings = False
-
Hope this helps.
- Minion -
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. -
DoCmd.SetWarnings = False
-
Hope this helps.
- Minion -
Sign in to post your reply or Sign up for a free account.
Similar topics |
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, frmNewMatter, for adding new records to the db.
The form is based on tblFile and has a subform based on tblContact,
|
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 INTO Table ( ID, Cod, CodArt, Q1, DataUscita )
VALUES (pID, pCod, pCod, pQ1, pDataUscita);
|
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 varchar
Comments varchar allows null values
|
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 primary key insert didnt work
either. I can run the SP manually in Visual Studio .NET and it works. When
i try to do this it doesn't.
Any help is greatly appreciated... newbie here as well so please be gentle
:)
ALTER PROCEDURE dbo.AddJob
|
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 parameters. It returns my error text
message in another output parameter as "ok", which is the value that is set
in the stored procedure prior to doing the insert. It returns my var for
@@rowcount as 1. However, the record does not get into the table.
...
| |
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 deleted.
'TempCart' has the following columns:
UserID int (no NULLs)
Carpet int (NULLs allowed)
Color int (NULLs allowed)
Engine int (NULLs allowed)
Total decimal(10, 2) (NULLs allowed)
|
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 and run it once you've made sure
there is no harmful code.
Currently we have several stored procedures which final
result is a select with several joins that returns many
|
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 sql server is my backend server.
This error occured whenever i step through and when it reaches rs.update it jux hangs down there and thereafter it shwn the aforementioned error. I am using the RecordSet properties to add the values. Can I use...
|
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 ATTACHING A SAMPLE PROCEDURE IT WAS NOT WORKING PERFECTLY. HELP ME
--exec SP_Generate_Insert_Statements tbl_Attachment,1
--select * from tbl_Attachmenttesting
--exec SP_Generate_Insert_Statements tbl_Attachmenttesting,1
ALTER PROCEDURE .
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |