Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

doing more with data controls

Posted on 2000-02-17
3
Medium Priority
?
174 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 60 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

971 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