wind20mph
MS Access User Since 1996
- Local time
- Tomorrow, 03:49
- Joined
- Mar 5, 2013
- Messages
- 50
Inserting data from History Table LIKE "P" Type into Preventive Maintenance Table and LIKE "R" Type into Repair Table.
I don't quiet get it because it says "PM Data Update" but nothing happened.
Below is the code:
Any assistance, enlightenment, help would be greatly appreciated.
Thanks in Advance.
I don't quiet get it because it says "PM Data Update" but nothing happened.
Below is the code:
Code:
[FONT=Tahoma][SIZE=2][COLOR=Red]Private Sub cmdUpdate_Click()
Dim strSQL
Dim dbMNT As Database
Dim rstHist As Recordset
Dim rstPM As Recordset
Dim rstRep As Recordset
Set dbMNT = CurrentDb()
Set rstHist = dbMNT.OpenRecordset("SELECT * FROM history ")
Set rstPM = dbMNT.OpenRecordset("SELECT * FROM pm ")
Set rstRep = dbMNT.OpenRecordset("SELECT * FROM repair ")
If rstHist.RecordCount >= 1 Then
Do Until rstHist.EOF = True
If rstPM.RecordCount > 0 Then
strSQL = "INSERT INTO pm(pmno, id, [desc], otherinfo ) SELECT history.refno, history.id, history.act, history.sparts FROM history WHERE (((history.reftype) LIKE 'P'));"
DoCmd.RunSQL (strSQL)
rstHist.MoveNext
Else
Exit Do
End If
If rstRep.RecordCount > 0 Then
strSQL = "INSERT INTO repair(bdate, id, refno, [desc], otherinfo) SELECT history.hdate, history.id, history.refno, history.act, history.sparts FROM history WHERE (((history.reftype) Like 'R'));"
DoCmd.RunSQL (strSQL)
rstHist.MoveNext
Else
Exit Do
End If
Loop
MsgBox "PM Data Update", vbInformation + vbOKOnly, "Updated"
Else
MsgBox "Nothing to Update", vbInformation + vbOKOnly, "Nothing"
End If
rstHist.Close
End Sub[/COLOR][/SIZE][/FONT]

Thanks in Advance.