473,769 Members | 6,838 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add and update data to multiple tables

jpr
Hello,

I know that this is not the rule but need some help. My datbase has
three tables:
MASTER
TEMPLATES
FORMS

I have a form which is based on a table named MASTER.
I have a primary key set to autonumber and a field SSN which I would
like to add from this form at the same time also into the tables
TEMPLATE and FORMS.

I would like a code that verifies if in table MASTER, a record with
that SSN already exists. If YES, then it should only update the
modified data, save the records, and reopen the form on the recordset I
was working on based on that SSN (basically the last one opened).

If the SSN does not exist, well I would like a code that would append
all the data into the table MASTER and the SSN field into the same
field of the tables TEMPLATES and FORMS.

Any help?

Mar 25 '06 #1
3 3544
jpr wrote:
Hello,

I know that this is not the rule but need some help. My datbase has
three tables:
MASTER
TEMPLATES
FORMS

I have a form which is based on a table named MASTER.
I have a primary key set to autonumber and a field SSN which I would
like to add from this form at the same time also into the tables
TEMPLATE and FORMS.

I would like a code that verifies if in table MASTER, a record with
that SSN already exists. If YES, then it should only update the
modified data, save the records, and reopen the form on the recordset I
was working on based on that SSN (basically the last one opened).

If the SSN does not exist, well I would like a code that would append
all the data into the table MASTER and the SSN field into the same
field of the tables TEMPLATES and FORMS.

Any help?

I don't know if I understand your question. I would think SSN would be
a lookup/filter field. IOW, it does not have a control source.

In the BeforeUpdate event of SSN, you would check for the existence of
that SSN in Master. If so, move to that record. If it doesn't exist,
ask the op if they want to add the SSN. Update, then go to that record.

I have no idea what you want to update/add. Consider the following a
template.

Dim rstTemplate As Recordset
Dim rstForms As Recordset
Dim rst As Recordset
set rst = Me.Recordsetclo ne
rst.findfirst "SSN = '" & Me.SSN & "'"
if Not rst.NoMatch 'record found
'go to that record
Me.Bookmark = rst.Bookmark
ElseIF msgbox("SSN not found. Do you want to add it?",_
vbYesNo,"Add it?") = vbYes then
rst.AddNew
rst!SSN = Me.SSN
rst.Update
rst.bookmark = rst.LastModifie d

set rstTemplate = Currentdb.openr ecordset("Templ ate",dbopendyna set)
rstTemplate.Add New
rstTemplate!SSN = Me.SSN
rstTemplate.Upd ate

set rstForms = Currentdb.openr ecordset("Forms ",dbopendynaset )
rstrstForms.Add New
rstrstForms!SSN = Me.SSN
rstrstForms.Upd ate

Me.BookMark = rst.Bookmark
rst.close
rstTemplate.clo se
rstForms.Closet
set rst = Nothing
set rstTemplate = Nothing
set rstForms = Nothing

else
Cancel = True
Endif

Mar 25 '06 #2
jpr
Hello, thank you for your help.
I will try to summarize what I am trying to achieve with my database
which will handle a list of clients of a small insurance company.

My program has three main tables:

MASTER
TEMPLATES
FORMS

All three tables have different fields with the exception of the field
ID which is the primary key (auto number) and the field SSN which I
have decided to place in all three tables.
Each record (in my case each Client) will be recognized by the SSN and
duplicates are not allowed.

I will use a form named MASTER with its record source to the table
MASTER, to add a new record or to modify existing ones. To add a new
record I use the following code behind a command button from a Menu
form:

DoCmd.OpenForm ("Master")
DoCmd.GoToRecor d , , acNewRec

To modify a record I use a list box with source to a query.

What I am trying to achieve is a way to save my data at the same time
in the above three tables.

In the tables TEMPLATES and FORMS only the SSN will be saved unless
that SSN already exists (I will need a code to verify if that SSN has
already been entered. If no, the SSN can be added to TEMPLATES and
FORMS tables).
In the table MASTER any new or modified data should be saved. The SSN
field in my MASTER form is the first field to be completed and has a
code that on the after update checks if a record with that SSN has
already been entered. If yes, it closes the form.

The code I have simply saves the data into the table MASTER.

What I would like to save the data and then return to the record I had
active in my form MASTER.

Is there a way I can do this by adding a code some where?
Thanks.

Mar 27 '06 #3
jpr wrote:
Hello, thank you for your help.
I will try to summarize what I am trying to achieve with my database
which will handle a list of clients of a small insurance company.

My program has three main tables:

MASTER
TEMPLATES
FORMS

All three tables have different fields with the exception of the field
ID which is the primary key (auto number) and the field SSN which I
have decided to place in all three tables.
Each record (in my case each Client) will be recognized by the SSN and
duplicates are not allowed.

I will use a form named MASTER with its record source to the table
MASTER, to add a new record or to modify existing ones. To add a new
record I use the following code behind a command button from a Menu
form:

DoCmd.OpenForm ("Master")
DoCmd.GoToRecor d , , acNewRec

To modify a record I use a list box with source to a query.

What I am trying to achieve is a way to save my data at the same time
in the above three tables.

In the tables TEMPLATES and FORMS only the SSN will be saved unless
that SSN already exists (I will need a code to verify if that SSN has
already been entered. If no, the SSN can be added to TEMPLATES and
FORMS tables).
In the table MASTER any new or modified data should be saved. The SSN
field in my MASTER form is the first field to be completed and has a
code that on the after update checks if a record with that SSN has
already been entered. If yes, it closes the form.

The code I have simply saves the data into the table MASTER.

What I would like to save the data and then return to the record I had
active in my form MASTER.

Is there a way I can do this by adding a code some where?
Thanks.

Hmmmm...Maybe in the AfterUpdate event of the form open up a recordset
for Templates and Forms and search for the SSN in each. If they don't
exist, do an AddNew, set SSN to the MasterSSN, and then Update.

I wouldn't know how you plan to update a master SSN if it changes...lets
say from 111-222-3333 to 111-222-3334? You'll need to update the
Templates and Forms too.

I kinda understand your dilemma. It's a bit difficult to describe fully
all of the nuances w/o getting the reader overwhelmed and still make sense.
Mar 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
31129
by: Rima | last post by:
I have the following two tables : table a (commit_id, capital_market_id, chg_lst_date ) table b (b_seq_id,
1
2994
by: Wing | last post by:
Hi all, I have created 2 tables in sql database and join these 2 tables before assign the result to the dataset, and display the result in datagrid. Everything is fine up to this point. The problem come up when I want to delete one of rows in datagrid and update the change to the corresponding table. The error msg show up "Dynamic SQL generation is not supported against multiple base tables."
9
12989
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from northwind database that has an employees, orders, and order details. the following are the 3 tables in my sql database students schyrsem
1
1567
by: Foef | last post by:
When I have a stored procedure, with multiple tables in MS Access, in a dataset and I change it in my DataGrid, I get the next message when I want to update my DataSet: InvalidOperationException: "Dynamic SQL generation is not supported against a SelectCommand that does not return any base table information." I tried to use an update query but when I fill my DataTable using myDataAdapter.Fill(myDataSet, myTable)
8
2697
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. Example: I have a dataadapter that contains one table with one row. I change the value of the 'FisrtName' column in that row from Jack to John. I call ..update on the dataadapter it goes through fine. Now I change that same column in that same row...
6
4679
by: shil | last post by:
Hi, I am writing a windows app in .net 2003. I have a datagrid which gets data from a storedprocedure. My question is how can I update the data in the datagrid? I want to call another storedprocedure to update the data in the datagrid. Thanks in advance.
1
2089
by: andrewcw | last post by:
I have just 1 table that I am updating, the SQL I use to generate the DataTable is complex using multiple tables, however when I view the fieldnames of the DataTable from the DataSet - everything matches: What dont I understand here: ( The error I get is : Dynamic SQL generation is not supported against multiple base tables ). But My DataSet is 1 Table, and my target is 1 table, Why the error ?? Thanks : try {
2
3066
by: Presto | last post by:
I am making a front end mdb so users can enter new members data. I can then import this into the master database on the backend and erase the existing info on the front end to keep the data reasonably secure. ( I borrowed the code from http://www.databasedev.co.uk/unbound-forms-add-data.html example) I have 4 tables that will be updated from this form: Members ContactInfo Payments
5
4080
by: Bogdan | last post by:
Hi, I have a stored procedure that uses JOINs to return columns from multiple tables. I also have another stored proc that that takes a series of params and updates multiple tables. I used the framework to auto-generate a table adapter specifying both stored procs as Get/Fill and Update. The problem is that columns from the JOINed table seem to marked as 'read-only' so trying to update a row results in an exception. BTW, by default a...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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,...
0
10222
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9866
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
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 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...
0
6675
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();...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
bsmnconsultancy
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...

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.