J
jim
Here's my code in a pop-up form:
Option Compare Database
Option Explicit
Private Sub ContactName_AfterUpdate()
Dim txtCustomerName As String
Dim txtBuildingNo As Integer
If NewRecord Then 'When a new contact
is added assign next Contact Number for Building
If DCount("ContactNo", "tblClientBuildContacts", "[CustomerName] =
""" & txtCustomerName & """ AND [BuildingNo] = " & txtBuildingNo) = 0 Then
'"[CustomerName] = """ & Me!CustomerName & """ And [BuildingNo]
= " & Me!BuildingNo
Me.txtContactNo = 1
Else
Me.txtContactNo = DMax("ContactNo", "tblCustomerContacts",
"[CustomerName] = """ & txtCustomerName & """ AND [BuildingNo] = " &
txtBuildingNo) + 1
End If
End If
End Sub
Private Sub Form_Open(Cancel As Integer)
Dim txtCustomerName As String
Dim txtBuildingNo As Integer
If IsNull(OpenArgs) = False Then
Dim arrArgs() As String
arrArgs = Split(Me.OpenArgs, ",")
txtCustomerName = arrArgs(0)
txtBuildingNo = arrArgs(1)
End If
End Sub
And in the calling form I have:
Private Sub Option96_Click()
Dim strOpenArgs As String
strOpenArgs = Me.txtCustomerName & "," & Me.txtBuildingNo
DoCmd.OpenForm "sfrmClientBuildContacts", , , "[CustomerName] = """ &
Me!CustomerName & """ And [BuildingNo] = " & Me!BuildingNo, , , strOpenArgs
.....which is working very good.
The problem is in the Sub ContactName_AfterUpdate. Somehow the variable
txtCustomerName is lost and shows null in debug mode. The other variable,
txtBuildingNo is fine. So when I try to add a record it fails because
CustomerName is a required field. Why is the variable lost? I tried
defining them twice but this also does not work.
Option Compare Database
Option Explicit
Private Sub ContactName_AfterUpdate()
Dim txtCustomerName As String
Dim txtBuildingNo As Integer
If NewRecord Then 'When a new contact
is added assign next Contact Number for Building
If DCount("ContactNo", "tblClientBuildContacts", "[CustomerName] =
""" & txtCustomerName & """ AND [BuildingNo] = " & txtBuildingNo) = 0 Then
'"[CustomerName] = """ & Me!CustomerName & """ And [BuildingNo]
= " & Me!BuildingNo
Me.txtContactNo = 1
Else
Me.txtContactNo = DMax("ContactNo", "tblCustomerContacts",
"[CustomerName] = """ & txtCustomerName & """ AND [BuildingNo] = " &
txtBuildingNo) + 1
End If
End If
End Sub
Private Sub Form_Open(Cancel As Integer)
Dim txtCustomerName As String
Dim txtBuildingNo As Integer
If IsNull(OpenArgs) = False Then
Dim arrArgs() As String
arrArgs = Split(Me.OpenArgs, ",")
txtCustomerName = arrArgs(0)
txtBuildingNo = arrArgs(1)
End If
End Sub
And in the calling form I have:
Private Sub Option96_Click()
Dim strOpenArgs As String
strOpenArgs = Me.txtCustomerName & "," & Me.txtBuildingNo
DoCmd.OpenForm "sfrmClientBuildContacts", , , "[CustomerName] = """ &
Me!CustomerName & """ And [BuildingNo] = " & Me!BuildingNo, , , strOpenArgs
.....which is working very good.
The problem is in the Sub ContactName_AfterUpdate. Somehow the variable
txtCustomerName is lost and shows null in debug mode. The other variable,
txtBuildingNo is fine. So when I try to add a record it fails because
CustomerName is a required field. Why is the variable lost? I tried
defining them twice but this also does not work.