Solved

doing more with data controls

Posted on 2000-02-17
3
165 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
ID: 2530491
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
ID: 2531197
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
ID: 2532636
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 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

20 Experts available now in Live!

Get 1:1 Help Now