473,407 Members | 2,326 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,407 software developers and data experts.

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 3523
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.Recordsetclone
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.LastModified

set rstTemplate = Currentdb.openrecordset("Template",dbopendynaset)
rstTemplate.AddNew
rstTemplate!SSN = Me.SSN
rstTemplate.Update

set rstForms = Currentdb.openrecordset("Forms",dbopendynaset)
rstrstForms.AddNew
rstrstForms!SSN = Me.SSN
rstrstForms.Update

Me.BookMark = rst.Bookmark
rst.close
rstTemplate.close
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.GoToRecord , , 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.GoToRecord , , 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
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
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...
9
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...
1
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: ...
8
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. ...
6
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...
1
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...
2
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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
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
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...

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.