473,666 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unbound Form to update multiple tables

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...-add-data.html example)

I have 4 tables that will be updated from this form:
Members
ContactInfo
Payments
History

I can get it to update the Members table with no problem, but it errors out
when we go beyond that.
I marked the spot where it errors out. The Members table gets updated but
not the rest.

Here's a look at the code:
-----------------------------------------------------------------
Private Sub cmdAddNewMember _Click()
Dim err As Integer
Dim cnn1 As ADODB.Connectio n
Dim rstcontact As ADODB.Recordset
Dim strCnn As String

'Check that all fields are filled in
FirstName.SetFo cus
If FirstName.Text = "" Then
err = err + 1
MsgBox "Please fill in the First Name box!" & err
End If

LastName.SetFoc us
If LastName.Text = "" Then
err = err + 1
MsgBox "Please fill in the Last Name box!" & err
End If

'if no errors insert data
If err < 1 Then
' Open a connection.
Set cnn1 = New ADODB.Connectio n
mydb = "U:\Apps\Office \AddNewMembers. mdb"
strCnn = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & mydb
cnn1.Open strCnn

' Open Members table.
Set rstMembers = New ADODB.Recordset
rstMembers.Curs orType = adOpenKeyset
rstMembers.Lock Type = adLockOptimisti c
rstMembers.Open "Members", cnn1, , , adCmdTable

'get the new Members data
rstMembers.AddN ew
rstMembers!Firs tName = FirstName
rstMembers!Last Name = LastName
rstMembers.Upda te

' Show the newly added data.
MsgBox "New Members: " & rstMembers!Firs tName & "has been
successfully added"
'close connection to the Members table
rstMembers.Clos e

' *** THIS IS WHERE IT STOPS AND ERRORS OUT AFTER THIS LINE *
' Open ContactInfo table.
Set rstContactInfo = New ADODB.Recordset
rstContactInfo. CursorType = adOpenKeyset
rstContactInfo. LockType = adLockOptimisti c
rstContactInfo. Open "ContactInf o", cnn1, , , adCmdTable
'get the new record data
rstContactInfo. AddNew
rstContactInfo! Address1Line1 = Address1Line1
rstContactInfo! Address1Line2 = Address1Line2
rstContactInfo. Update

rstContactInfo. Close

' Open Status table.
Set rstStatus = New ADODB.Recordset
rstStatus.Curso rType = adOpenKeyset
rstStatus.LockT ype = adLockOptimisti c
rstStatus.Open "Status", cnn1, , , adCmdTable
'get the new Status data
rstStatus.AddNe w
rstStatus!Activ e = Active
rstStatus!Paid = Paid
rstStatus.Close
' Open Payments table.
Set rstPayments = New ADODB.Recordset
rstPayments.Cur sorType = adOpenKeyset
rstPayments.Loc kType = adLockOptimisti c
rstPayments.Ope n "Payments", cnn1, , , adCmdTable
'get the new Payments data
rstPayments.Add New
rstPayments!Pay mentType = PaymentType
rstPayments!Amo untPaid = AmountPaid
rstPayments!Mem bershipType = MembershipType
rstPayments.Clo se

' Open History table.
Set rstHistory = New ADODB.Recordset
rstHistory.Curs orType = adOpenKeyset
rstHistory.Lock Type = adLockOptimisti c
rstHistory.Open "History", cnn1, , , adCmdTable
'get the new History data
rstHistory.AddN ew
rstHistory!Hist oryYear = Year
rstHistory!Spon soredBy = SponsoredBy
rstHistory!Hist oryNotes = HistoryNotes
rstHistory.Clos e

'Close connection to the database after all updates to the tables
cnn1.Close

Else
MsgBox "An Error has occurred, please check and try again"
End If

End Sub
Jun 27 '08 #1
2 3060
On Sat, 19 Apr 2008 18:23:55 -0400, "Presto" <ju******@prest oweb.net>
wrote:

"It errors out": you probably say that because you get an error
message "An Error has occurred, please check and try again"
but that error handler is HORRIBLE. You as a developer (and us trying
to help) deserve an accurate message, at least Err.Description , and
perhaps also Err.Number.

The only valid reason why the line:
Set rstContactInfo = New ADODB.Recordset
would fail is if the recordset variable rstContactInfo was not
declared, as it appears to be.
Add a line:
Dim rstContactInfo As ADODB.Recordset
to the top of the procedure.

There are many other things not to like about your code, but they are
beyond the scope of your immediate question.

-Tom.
>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...-add-data.html example)

I have 4 tables that will be updated from this form:
Members
ContactInfo
Payments
History

I can get it to update the Members table with no problem, but it errors out
when we go beyond that.
I marked the spot where it errors out. The Members table gets updated but
not the rest.

Here's a look at the code:
-----------------------------------------------------------------
Private Sub cmdAddNewMember _Click()
Dim err As Integer
Dim cnn1 As ADODB.Connectio n
Dim rstcontact As ADODB.Recordset
Dim strCnn As String

'Check that all fields are filled in
FirstName.SetF ocus
If FirstName.Text = "" Then
err = err + 1
MsgBox "Please fill in the First Name box!" & err
End If

LastName.SetFo cus
If LastName.Text = "" Then
err = err + 1
MsgBox "Please fill in the Last Name box!" & err
End If

'if no errors insert data
If err < 1 Then
' Open a connection.
Set cnn1 = New ADODB.Connectio n
mydb = "U:\Apps\Office \AddNewMembers. mdb"
strCnn = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & mydb
cnn1.Open strCnn

' Open Members table.
Set rstMembers = New ADODB.Recordset
rstMembers.Curs orType = adOpenKeyset
rstMembers.Lock Type = adLockOptimisti c
rstMembers.Open "Members", cnn1, , , adCmdTable

'get the new Members data
rstMembers.Add New
rstMembers!Firs tName = FirstName
rstMembers!Last Name = LastName
rstMembers.Upda te

' Show the newly added data.
MsgBox "New Members: " & rstMembers!Firs tName & "has been
successfully added"
'close connection to the Members table
rstMembers.Clo se

' *** THIS IS WHERE IT STOPS AND ERRORS OUT AFTER THIS LINE *
' Open ContactInfo table.
Set rstContactInfo = New ADODB.Recordset
rstContactInfo. CursorType = adOpenKeyset
rstContactInfo. LockType = adLockOptimisti c
rstContactInfo. Open "ContactInf o", cnn1, , , adCmdTable
'get the new record data
rstContactInfo .AddNew
rstContactInfo! Address1Line1 = Address1Line1
rstContactInfo! Address1Line2 = Address1Line2
rstContactInfo. Update

rstContactInfo .Close

' Open Status table.
Set rstStatus = New ADODB.Recordset
rstStatus.Curso rType = adOpenKeyset
rstStatus.LockT ype = adLockOptimisti c
rstStatus.Open "Status", cnn1, , , adCmdTable
'get the new Status data
rstStatus.AddN ew
rstStatus!Activ e = Active
rstStatus!Paid = Paid
rstStatus.Clos e
' Open Payments table.
Set rstPayments = New ADODB.Recordset
rstPayments.Cur sorType = adOpenKeyset
rstPayments.Loc kType = adLockOptimisti c
rstPayments.Ope n "Payments", cnn1, , , adCmdTable
'get the new Payments data
rstPayments.Ad dNew
rstPayments!Pay mentType = PaymentType
rstPayments!Amo untPaid = AmountPaid
rstPayments!Mem bershipType = MembershipType
rstPayments.Cl ose

' Open History table.
Set rstHistory = New ADODB.Recordset
rstHistory.Curs orType = adOpenKeyset
rstHistory.Lock Type = adLockOptimisti c
rstHistory.Open "History", cnn1, , , adCmdTable
'get the new History data
rstHistory.Add New
rstHistory!Hist oryYear = Year
rstHistory!Spon soredBy = SponsoredBy
rstHistory!Hist oryNotes = HistoryNotes
rstHistory.Clo se

'Close connection to the database after all updates to the tables
cnn1.Close

Else
MsgBox "An Error has occurred, please check and try again"
End If

End Sub
Jun 27 '08 #2
Sorry if the code seems "horrible" but as I stated on the first post, this
was borrowed from an example that exists online and I'm trying to convert it
to fit my db. I'm not a code master.... but I am trying to do as much as I
can.
If there is a better way to get all the fields to update to the correct
tables that would be great. Please post a url to an example db..

"Tom van Stiphout" <no************ *@cox.netwrote in message
news:v1******** *************** *********@4ax.c om...
On Sat, 19 Apr 2008 18:23:55 -0400, "Presto" <ju******@prest oweb.net>
wrote:

"It errors out": you probably say that because you get an error
message "An Error has occurred, please check and try again"
but that error handler is HORRIBLE. You as a developer (and us trying
to help) deserve an accurate message, at least Err.Description , and
perhaps also Err.Number.

The only valid reason why the line:
Set rstContactInfo = New ADODB.Recordset
would fail is if the recordset variable rstContactInfo was not
declared, as it appears to be.
Add a line:
Dim rstContactInfo As ADODB.Recordset
to the top of the procedure.

There are many other things not to like about your code, but they are
beyond the scope of your immediate question.

-Tom.
>>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...-add-data.html example)

I have 4 tables that will be updated from this form:
Members
ContactInfo
Payments
History

I can get it to update the Members table with no problem, but it errors
out
when we go beyond that.
I marked the spot where it errors out. The Members table gets updated but
not the rest.

Here's a look at the code:
-----------------------------------------------------------------
Private Sub cmdAddNewMember _Click()
Dim err As Integer
Dim cnn1 As ADODB.Connectio n
Dim rstcontact As ADODB.Recordset
Dim strCnn As String

'Check that all fields are filled in
FirstName.Set Focus
If FirstName.Text = "" Then
err = err + 1
MsgBox "Please fill in the First Name box!" & err
End If

LastName.SetF ocus
If LastName.Text = "" Then
err = err + 1
MsgBox "Please fill in the Last Name box!" & err
End If

'if no errors insert data
If err < 1 Then
' Open a connection.
Set cnn1 = New ADODB.Connectio n
mydb = "U:\Apps\Office \AddNewMembers. mdb"
strCnn = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & mydb
cnn1.Open strCnn

' Open Members table.
Set rstMembers = New ADODB.Recordset
rstMembers.Curs orType = adOpenKeyset
rstMembers.Lock Type = adLockOptimisti c
rstMembers.Open "Members", cnn1, , , adCmdTable

'get the new Members data
rstMembers.Ad dNew
rstMembers!Firs tName = FirstName
rstMembers!Last Name = LastName
rstMembers.Upda te

' Show the newly added data.
MsgBox "New Members: " & rstMembers!Firs tName & "has been
successfull y added"
'close connection to the Members table
rstMembers.Cl ose

' *** THIS IS WHERE IT STOPS AND ERRORS OUT AFTER THIS LINE *
' Open ContactInfo table.
Set rstContactInfo = New ADODB.Recordset
rstContactInfo. CursorType = adOpenKeyset
rstContactInfo. LockType = adLockOptimisti c
rstContactInfo. Open "ContactInf o", cnn1, , , adCmdTable
'get the new record data
rstContactInf o.AddNew
rstContactInfo! Address1Line1 = Address1Line1
rstContactInfo! Address1Line2 = Address1Line2
rstContactInfo. Update

rstContactInf o.Close

' Open Status table.
Set rstStatus = New ADODB.Recordset
rstStatus.Curso rType = adOpenKeyset
rstStatus.LockT ype = adLockOptimisti c
rstStatus.Open "Status", cnn1, , , adCmdTable
'get the new Status data
rstStatus.Add New
rstStatus!Activ e = Active
rstStatus!Paid = Paid
rstStatus.Clo se
' Open Payments table.
Set rstPayments = New ADODB.Recordset
rstPayments.Cur sorType = adOpenKeyset
rstPayments.Loc kType = adLockOptimisti c
rstPayments.Ope n "Payments", cnn1, , , adCmdTable
'get the new Payments data
rstPayments.A ddNew
rstPayments!Pay mentType = PaymentType
rstPayments!Amo untPaid = AmountPaid
rstPayments!Mem bershipType = MembershipType
rstPayments.C lose

' Open History table.
Set rstHistory = New ADODB.Recordset
rstHistory.Curs orType = adOpenKeyset
rstHistory.Lock Type = adLockOptimisti c
rstHistory.Open "History", cnn1, , , adCmdTable
'get the new History data
rstHistory.Ad dNew
rstHistory!Hist oryYear = Year
rstHistory!Spon soredBy = SponsoredBy
rstHistory!Hist oryNotes = HistoryNotes
rstHistory.Cl ose

'Close connection to the database after all updates to the tables
cnn1.Close

Else
MsgBox "An Error has occurred, please check and try again"
End If

End Sub

Jun 27 '08 #3

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

Similar topics

11
17276
by: deko | last post by:
I need to create different recordsets based on queries that use data from unbound fields in a form. I've discovered that I can't do this, and instead need to save the data in question (usually a text string) to a table. I'm thinking the best way to do this is to use a Make Table query -- that way the table stays small -- one row -- and there is less chance for something to get overwritten. But how to create a make table query from...
5
2940
by: David | last post by:
Hi I seem to be getting nowhere with this. I am opening a form which will be used to input Notes into different fields in a table. My problem is changing the unbound field name to the field name in the associated table that this form is based on. Is there anyway I can do this with vba ? I am using a different button object to open this form for the field it is to update. button1 updates unbound field name from text1 to 101Commnets...
4
1926
by: Bill Stock | last post by:
The few times in the past that I've loaded unbound data, I've tended to cheat and use temp tables (not really unbound) or use code for small datasets. I'm currently involved in a project that has numerous tables in the 200 column range, with several thousand rows of data. A consulting review prior to my involvement stressed the wasted space and database speed as the major impetus for normalization. Although the db actually works fairly...
7
1801
by: Max | last post by:
I've included the needed tables in the DataSource. Those tables that are bound to controls I can workwith. But how do you get access to the DataAdaptors that are not bound? me.Dataset1.table is a table with no Insert or Update methods. pll.DataSet1.table has the Row, ChangeEvent, and ChangeEventHandler. It seems like it should be fairly straight forward to use the DataAdapter without binding it to a control. How do you do this?
1
3064
by: planetthoughtful | last post by:
Hi All, I have a mainform with a subform in which I show some task summary data. On the mainform I have a number of unbound controls that reflect values relevant to each task in the subform. The unbound controls are populated in the subform's OnCurrent even from a number of different tables related to the records in tbl_tasks, which is the recordset displayed in the subform.
18
3785
by: TORQUE | last post by:
Hi, Im wondering if anyone can help me with a problem. I have a form with more than 50 unbound fields. Some of the fields will be blank from time to time. This seems to be where im having trouble. I have tried keeping some of the fields bound and when I use the save button it has been saving as 2 different records. This is unacceptable. This is what I have, can anyone help me out with this?
2
5167
by: tricard | last post by:
Good day all, I am in the process of creating a form used to enter new purchase orders. The thing is that I do not want to bind the form to a record set; instead I will use a SQL insert statement in VBA to update the tables once all the data is entered on the form. I have three fields (single record) to fill out for the table tblPurchaseOrder and three fields (multiple records) to fill out for table tblPODetails. The tblPurchaseOrder...
10
3490
by: themightypea | last post by:
Hi, I'm attempting to create a continuos form which allow the user to edit various fields for each item. Unfortunately, the data I need is spread over multiple tables so binding the control to the item in the underlying query prevents me from editing it. To get round this I've bound the controls to functions returning the data from an array, similar to the method described in http://www.thescripts.com/forum/thread193301.html. When the user...
6
2676
by: Volker Neurath | last post by:
Hi all, I have a Problem with combobox-property "NotInList" and an unbound Form. The situation: On my main form i have three comboboxes for data-exchange (here: Names of distributor, reseller and final customers, the whole database is made for storing information about quotatations - no, not for quoting itself) ut the boxes actually may not contain all our distributors and reseller's
0
8448
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...
1
8552
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,...
0
8640
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
6198
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
5666
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
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2773
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
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
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.