V
vbnetman via AccessMonster.com
Good morning,
I will start with an overview of my plan. I have 3 tables arranged as follows:
(may need to sketch this one)
Table1:
UnitID – PK
MeterID – PK
(plus other fields)
Table2:
UnitID – PK (FK to Table1, UnitID)
MeterID – PK (FK to Table1, MeterID)
ReplacementNo – PK
(plus other fields)
Table3:
OrderID – PK – autonumber
UnitID – PK (FK to Table2, UnitID
MeterID – PK (FK to Table2, MeterID)
ReplacementNo – PK (FK to Table2, ReplacementNo)
(plus other fields)
The arrangement is used to track various meters on equipment. A unit can have
several meters like hourmeter, odometer etc. Thus, unit1 can have meter1,
meter2 and so on. Over time, meter1 may fail and need to be replaced. It is
replaced by another ‘meter1’ but is flagged as a replacement, allowing it to
remain as ‘meter1’. Table1 is used as a historical table, storing a
cumulative total for a particular unit and its associated meter. Table 2
stores info specific to each meter like whether its been replaced and the
maximum reading like 9999. Finally, Table3 stores meter readings and date
read among other thing. I know this may be exhaustive. Here’s my dilemma.
After Table 1 is populated with data at the form level, I want to run 2
append queries that copy UnitID and MeterID from Table 1 to Table 2 and Table
3 simultaneously. I have been successful with this with the following code
however I need to run it twice. The first run populates Table 2 – the second
run populates Table 3. Not sure why but I think that the record is not
actually saved to the table until I move off of the record. Then, I can go
back and do it again. I would like to accomplish this in one pass. I’m
thinking there is code that that can be added to save the record, allowing
this process to occur. Does anyone have any thoughts or different approach
suggestions?
Thank you
Private Sub Command4_Click()
On Error GoTo Err_Command4_Click
Dim stDocName As String
Dim stdocnames As String
stDocName = "query3"
stdocnames = "query4"
DoCmd.OpenQuery stdocnames, acNormal, acAdd
DoCmd.OpenQuery stDocName, acNormal, acAdd
Exit_Command4_Click:
Exit Sub
Err_Command4_Click:
MsgBox Err.description
Resume Exit_Command4_Click
End Sub
I will start with an overview of my plan. I have 3 tables arranged as follows:
(may need to sketch this one)
Table1:
UnitID – PK
MeterID – PK
(plus other fields)
Table2:
UnitID – PK (FK to Table1, UnitID)
MeterID – PK (FK to Table1, MeterID)
ReplacementNo – PK
(plus other fields)
Table3:
OrderID – PK – autonumber
UnitID – PK (FK to Table2, UnitID
MeterID – PK (FK to Table2, MeterID)
ReplacementNo – PK (FK to Table2, ReplacementNo)
(plus other fields)
The arrangement is used to track various meters on equipment. A unit can have
several meters like hourmeter, odometer etc. Thus, unit1 can have meter1,
meter2 and so on. Over time, meter1 may fail and need to be replaced. It is
replaced by another ‘meter1’ but is flagged as a replacement, allowing it to
remain as ‘meter1’. Table1 is used as a historical table, storing a
cumulative total for a particular unit and its associated meter. Table 2
stores info specific to each meter like whether its been replaced and the
maximum reading like 9999. Finally, Table3 stores meter readings and date
read among other thing. I know this may be exhaustive. Here’s my dilemma.
After Table 1 is populated with data at the form level, I want to run 2
append queries that copy UnitID and MeterID from Table 1 to Table 2 and Table
3 simultaneously. I have been successful with this with the following code
however I need to run it twice. The first run populates Table 2 – the second
run populates Table 3. Not sure why but I think that the record is not
actually saved to the table until I move off of the record. Then, I can go
back and do it again. I would like to accomplish this in one pass. I’m
thinking there is code that that can be added to save the record, allowing
this process to occur. Does anyone have any thoughts or different approach
suggestions?
Thank you
Private Sub Command4_Click()
On Error GoTo Err_Command4_Click
Dim stDocName As String
Dim stdocnames As String
stDocName = "query3"
stdocnames = "query4"
DoCmd.OpenQuery stdocnames, acNormal, acAdd
DoCmd.OpenQuery stDocName, acNormal, acAdd
Exit_Command4_Click:
Exit Sub
Err_Command4_Click:
MsgBox Err.description
Resume Exit_Command4_Click
End Sub