M
Michael Beckinsale
Hi All,
Below is the sample code l have used to trigger events on a form and then
update a counter in another table. The code works as expected except that
when the form is returned for the next new record to be entered it does not
behave correctly in that a new record can be created , however if you want
to close the form it thinks that a null value is present and an error is
returned.
Please can anybody tell me what is wrong as l am going craaaaaaaaazy.
Sorry about the MsgBoxes but trying to de-bug.
Windows98 & Access97
Option Compare Database
Option Explicit
Dim cpcodeext1
Private Sub Form_AfterInsert()
DoCmd.OpenTable "GROUPBLBS"
MsgBox ("message 1")
[NEXT_OFA_CP_CODE] = cpcodeext1
MsgBox ("message 2")
DoCmd.Save
MsgBox ("message 3")
DoCmd.Close
MsgBox ("message 4")
End Sub
Private Sub OFA_BLB_CODE_LostFocus()
Dim intnewrec As Integer
Dim cpcode
Dim cpcodelen
Dim cpcodeext
MsgBox ("message 5")
intnewrec = Me.NewRecord
MsgBox ("message 6")
If intnewrec = True Then
MsgBox ("message 6")
cpcode = Format(Me![NEXT_OFA_CP_CODE], "##0")
MsgBox ("message 7")
cpcodelen = Len(cpcode)
MsgBox ("message 8")
If cpcodelen = 1 Then
MsgBox ("message 9")
cpcode = "00" & cpcode
MsgBox ("message 10")
End If
MsgBox ("message 11")
If cpcodelen = 2 Then
MsgBox ("message 12")
cpcode = "0" & cpcode
MsgBox ("message 13")
End If
MsgBox ("message 14")
If cpcodelen = 3 Then
MsgBox ("message 15")
cpcode = cpcode
MsgBox ("message 16")
End If
MsgBox ("message 17")
Me![OFA_CP_CODE] = Left(Me![OFA_BLB_CODE], 4) & "D" & cpcode
MsgBox ("message 18")
cpcodeext = (Me![NEXT_OFA_CP_CODE]) + 1
MsgBox ("message 19")
cpcodeext1 = cpcodeext
MsgBox ("message 20")
End If
End Sub
Private Sub OFA_CP_CODE_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub tbOFA_LOD2_CODE_GotFocus()
Dim intnewrec As Integer
intnewrec = Me.NewRecord
If intnewrec = True Then
Me![tbOFA_LOD2_CODE] = Left(Me![OFA_LOD1_CODE], 6) +
Left(Me![OFA_BLB_CODE], 4)
End If
End Sub
Regards
Michael Beckinsale
Below is the sample code l have used to trigger events on a form and then
update a counter in another table. The code works as expected except that
when the form is returned for the next new record to be entered it does not
behave correctly in that a new record can be created , however if you want
to close the form it thinks that a null value is present and an error is
returned.
Please can anybody tell me what is wrong as l am going craaaaaaaaazy.
Sorry about the MsgBoxes but trying to de-bug.
Windows98 & Access97
Option Compare Database
Option Explicit
Dim cpcodeext1
Private Sub Form_AfterInsert()
DoCmd.OpenTable "GROUPBLBS"
MsgBox ("message 1")
[NEXT_OFA_CP_CODE] = cpcodeext1
MsgBox ("message 2")
DoCmd.Save
MsgBox ("message 3")
DoCmd.Close
MsgBox ("message 4")
End Sub
Private Sub OFA_BLB_CODE_LostFocus()
Dim intnewrec As Integer
Dim cpcode
Dim cpcodelen
Dim cpcodeext
MsgBox ("message 5")
intnewrec = Me.NewRecord
MsgBox ("message 6")
If intnewrec = True Then
MsgBox ("message 6")
cpcode = Format(Me![NEXT_OFA_CP_CODE], "##0")
MsgBox ("message 7")
cpcodelen = Len(cpcode)
MsgBox ("message 8")
If cpcodelen = 1 Then
MsgBox ("message 9")
cpcode = "00" & cpcode
MsgBox ("message 10")
End If
MsgBox ("message 11")
If cpcodelen = 2 Then
MsgBox ("message 12")
cpcode = "0" & cpcode
MsgBox ("message 13")
End If
MsgBox ("message 14")
If cpcodelen = 3 Then
MsgBox ("message 15")
cpcode = cpcode
MsgBox ("message 16")
End If
MsgBox ("message 17")
Me![OFA_CP_CODE] = Left(Me![OFA_BLB_CODE], 4) & "D" & cpcode
MsgBox ("message 18")
cpcodeext = (Me![NEXT_OFA_CP_CODE]) + 1
MsgBox ("message 19")
cpcodeext1 = cpcodeext
MsgBox ("message 20")
End If
End Sub
Private Sub OFA_CP_CODE_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub tbOFA_LOD2_CODE_GotFocus()
Dim intnewrec As Integer
intnewrec = Me.NewRecord
If intnewrec = True Then
Me![tbOFA_LOD2_CODE] = Left(Me![OFA_LOD1_CODE], 6) +
Left(Me![OFA_BLB_CODE], 4)
End If
End Sub
Regards
Michael Beckinsale