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

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.Connection
Dim rstcontact As ADODB.Recordset
Dim strCnn As String

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

LastName.SetFocus
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.Connection
mydb = "U:\Apps\Office\AddNewMembers.mdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
cnn1.Open strCnn

' Open Members table.
Set rstMembers = New ADODB.Recordset
rstMembers.CursorType = adOpenKeyset
rstMembers.LockType = adLockOptimistic
rstMembers.Open "Members", cnn1, , , adCmdTable

'get the new Members data
rstMembers.AddNew
rstMembers!FirstName = FirstName
rstMembers!LastName = LastName
rstMembers.Update

' Show the newly added data.
MsgBox "New Members: " & rstMembers!FirstName & "has been
successfully added"
'close connection to the Members table
rstMembers.Close

' *** THIS IS WHERE IT STOPS AND ERRORS OUT AFTER THIS LINE *
' Open ContactInfo table.
Set rstContactInfo = New ADODB.Recordset
rstContactInfo.CursorType = adOpenKeyset
rstContactInfo.LockType = adLockOptimistic
rstContactInfo.Open "ContactInfo", 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.CursorType = adOpenKeyset
rstStatus.LockType = adLockOptimistic
rstStatus.Open "Status", cnn1, , , adCmdTable
'get the new Status data
rstStatus.AddNew
rstStatus!Active = Active
rstStatus!Paid = Paid
rstStatus.Close
' Open Payments table.
Set rstPayments = New ADODB.Recordset
rstPayments.CursorType = adOpenKeyset
rstPayments.LockType = adLockOptimistic
rstPayments.Open "Payments", cnn1, , , adCmdTable
'get the new Payments data
rstPayments.AddNew
rstPayments!PaymentType = PaymentType
rstPayments!AmountPaid = AmountPaid
rstPayments!MembershipType = MembershipType
rstPayments.Close

' Open History table.
Set rstHistory = New ADODB.Recordset
rstHistory.CursorType = adOpenKeyset
rstHistory.LockType = adLockOptimistic
rstHistory.Open "History", cnn1, , , adCmdTable
'get the new History data
rstHistory.AddNew
rstHistory!HistoryYear = Year
rstHistory!SponsoredBy = SponsoredBy
rstHistory!HistoryNotes = HistoryNotes
rstHistory.Close

'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 3042
On Sat, 19 Apr 2008 18:23:55 -0400, "Presto" <ju******@prestoweb.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.Connection
Dim rstcontact As ADODB.Recordset
Dim strCnn As String

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

LastName.SetFocus
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.Connection
mydb = "U:\Apps\Office\AddNewMembers.mdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
cnn1.Open strCnn

' Open Members table.
Set rstMembers = New ADODB.Recordset
rstMembers.CursorType = adOpenKeyset
rstMembers.LockType = adLockOptimistic
rstMembers.Open "Members", cnn1, , , adCmdTable

'get the new Members data
rstMembers.AddNew
rstMembers!FirstName = FirstName
rstMembers!LastName = LastName
rstMembers.Update

' Show the newly added data.
MsgBox "New Members: " & rstMembers!FirstName & "has been
successfully added"
'close connection to the Members table
rstMembers.Close

' *** THIS IS WHERE IT STOPS AND ERRORS OUT AFTER THIS LINE *
' Open ContactInfo table.
Set rstContactInfo = New ADODB.Recordset
rstContactInfo.CursorType = adOpenKeyset
rstContactInfo.LockType = adLockOptimistic
rstContactInfo.Open "ContactInfo", 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.CursorType = adOpenKeyset
rstStatus.LockType = adLockOptimistic
rstStatus.Open "Status", cnn1, , , adCmdTable
'get the new Status data
rstStatus.AddNew
rstStatus!Active = Active
rstStatus!Paid = Paid
rstStatus.Close
' Open Payments table.
Set rstPayments = New ADODB.Recordset
rstPayments.CursorType = adOpenKeyset
rstPayments.LockType = adLockOptimistic
rstPayments.Open "Payments", cnn1, , , adCmdTable
'get the new Payments data
rstPayments.AddNew
rstPayments!PaymentType = PaymentType
rstPayments!AmountPaid = AmountPaid
rstPayments!MembershipType = MembershipType
rstPayments.Close

' Open History table.
Set rstHistory = New ADODB.Recordset
rstHistory.CursorType = adOpenKeyset
rstHistory.LockType = adLockOptimistic
rstHistory.Open "History", cnn1, , , adCmdTable
'get the new History data
rstHistory.AddNew
rstHistory!HistoryYear = Year
rstHistory!SponsoredBy = SponsoredBy
rstHistory!HistoryNotes = HistoryNotes
rstHistory.Close

'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.com...
On Sat, 19 Apr 2008 18:23:55 -0400, "Presto" <ju******@prestoweb.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.Connection
Dim rstcontact As ADODB.Recordset
Dim strCnn As String

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

LastName.SetFocus
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.Connection
mydb = "U:\Apps\Office\AddNewMembers.mdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
cnn1.Open strCnn

' Open Members table.
Set rstMembers = New ADODB.Recordset
rstMembers.CursorType = adOpenKeyset
rstMembers.LockType = adLockOptimistic
rstMembers.Open "Members", cnn1, , , adCmdTable

'get the new Members data
rstMembers.AddNew
rstMembers!FirstName = FirstName
rstMembers!LastName = LastName
rstMembers.Update

' Show the newly added data.
MsgBox "New Members: " & rstMembers!FirstName & "has been
successfully added"
'close connection to the Members table
rstMembers.Close

' *** THIS IS WHERE IT STOPS AND ERRORS OUT AFTER THIS LINE *
' Open ContactInfo table.
Set rstContactInfo = New ADODB.Recordset
rstContactInfo.CursorType = adOpenKeyset
rstContactInfo.LockType = adLockOptimistic
rstContactInfo.Open "ContactInfo", 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.CursorType = adOpenKeyset
rstStatus.LockType = adLockOptimistic
rstStatus.Open "Status", cnn1, , , adCmdTable
'get the new Status data
rstStatus.AddNew
rstStatus!Active = Active
rstStatus!Paid = Paid
rstStatus.Close
' Open Payments table.
Set rstPayments = New ADODB.Recordset
rstPayments.CursorType = adOpenKeyset
rstPayments.LockType = adLockOptimistic
rstPayments.Open "Payments", cnn1, , , adCmdTable
'get the new Payments data
rstPayments.AddNew
rstPayments!PaymentType = PaymentType
rstPayments!AmountPaid = AmountPaid
rstPayments!MembershipType = MembershipType
rstPayments.Close

' Open History table.
Set rstHistory = New ADODB.Recordset
rstHistory.CursorType = adOpenKeyset
rstHistory.LockType = adLockOptimistic
rstHistory.Open "History", cnn1, , , adCmdTable
'get the new History data
rstHistory.AddNew
rstHistory!HistoryYear = Year
rstHistory!SponsoredBy = SponsoredBy
rstHistory!HistoryNotes = HistoryNotes
rstHistory.Close

'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
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...
5
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...
4
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...
7
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...
1
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....
18
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...
2
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...
10
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...
6
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
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,...

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.