Solved

doing more with data controls

Posted on 2000-02-17
3
163 Views
Last Modified: 2010-05-02
I have a data control setup on the form with a couple of bounded textboxes. I have two tables in the Access database. The bounded textboxes write directly to one of the tables. But I want to be able to update a record in the other table associated with the current record that was editted.  How do I do this as there seems to be no events for the data control to do this?
0
Comment
Question by:rukiman
3 Comments
 
LVL 2

Expert Comment

by:alokanant
Comment Utility
hi,
u can write the following code in the Save button of your form.


dim db as database
dim rs as recordset

' write code to open the database containing the other table

set rs = db.openrecordset("select * from OtherTable where relatedfld = '" & txtrelatedfld &"')
rs.edit
rs!fldtoupdate = txtval
....
rs.update
rs.close

hth
alok

hth
alok.
0
 
LVL 2

Accepted Solution

by:
p_biggelaar earned 20 total points
Comment Utility
The 'normal' (DAO) data control doessn't have those features. The Microsoft Ado Data Control does have events like:

Adodc1_RecordChangeComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
Adodc1_RecordsetChangeComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
Private Sub Adodc1_WillChangeField(ByVal cFields As Long, Fields As Variant, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
Private Sub Adodc1_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
Private Sub Adodc1_WillChangeRecordset(ByVal adReason As ADODB.EventReasonEnum, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)

In other words: using the ADODC will solve your problem.
0
 

Expert Comment

by:tcornett
Comment Utility
If the fields you want to update are the same, use "Enforce Referential Integrity".  For example, you have Table1 and Table2, both have a field called Index and the two tables are joined by this field.  In Access, create the relationship, choose Enforce Referential Integrity, and then Cascade Update Related Fields.  That way, when you change Index in Table1 from 1 to 2, it does the same in Table2.  By the way, the fields that would be linked must be part of the primary key of each table to use Referential Integrity.

- Tom
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now