G
Guest
I had a form (with Tab1 control) based on a table that incremented the
Home_Addr_PK field and everything worked well. Recently i changed the form to
be based on a query as i had to add Tab2. Tab2 contains the same control
tblAddress_Home_Addr_PK. When i fire the New_Home_Address button, the value
is always "HA0001" and not the correct value. What do i need to change.
Private Sub New_Home_Address_Click()
Dim strAddr As String
Dim intAddr As Integer
On Error GoTo Err_New_Home_Address_Click
DoCmd.GoToRecord , , acNewRec
strAddr = NZ(DMax("[tblAddress_Home_Addr_PK]", "tblAddress"). "HA0000")
intAddr = Val(Mid(strAddr, 3) ' extract numeric portion
If intAddr < 9999 Then
Me![tblAddress_Home_Addr_PK = Left(strAddr, 2) & Format(intAddr + 1, "0000")
Else
MsgBox "Turn off the computer - out of address numbers", vbOKOnly
End If
Exit_New_Home_Address_Click:
Exit Sub
Err_New_Home_Address_Click:
MsgBox Err.Description
Resume Exit_New_Home_Address_Click
End Sub
Home_Addr_PK field and everything worked well. Recently i changed the form to
be based on a query as i had to add Tab2. Tab2 contains the same control
tblAddress_Home_Addr_PK. When i fire the New_Home_Address button, the value
is always "HA0001" and not the correct value. What do i need to change.
Private Sub New_Home_Address_Click()
Dim strAddr As String
Dim intAddr As Integer
On Error GoTo Err_New_Home_Address_Click
DoCmd.GoToRecord , , acNewRec
strAddr = NZ(DMax("[tblAddress_Home_Addr_PK]", "tblAddress"). "HA0000")
intAddr = Val(Mid(strAddr, 3) ' extract numeric portion
If intAddr < 9999 Then
Me![tblAddress_Home_Addr_PK = Left(strAddr, 2) & Format(intAddr + 1, "0000")
Else
MsgBox "Turn off the computer - out of address numbers", vbOKOnly
End If
Exit_New_Home_Address_Click:
Exit Sub
Err_New_Home_Address_Click:
MsgBox Err.Description
Resume Exit_New_Home_Address_Click
End Sub