How to use OpenArgs

J

jim

Hi all, a pop-up form is opened from a subform with this code:

Private Sub Form_Open(Cancel As Integer)
Dim strCustomerName As String
Dim strBuildingNo As Long

If IsNull(OpenArgs) = False Then
Dim arrArgs() As String
arrArgs = Split(Me.OpenArgs, "~")
strCustomerName = arrArgs(0)
strBuildingNo = arrArgs(1)
End If
End Sub

It is working good and my array, arrArgs, is populating strCustomerName and
strBuildingNo perfectly. If a new record is needed I use the following:

Private Sub Form_BeforeUpdate(Cancel As Integer)
'Me!txtCustomerName.Value = Me!txtCustomerName.DefaultValue
'Me!CustomerName.Value =
Forms("sfrmClientBuildContacts").Controls("txtCustomerName").Value
' Me!BuildingNo.Value =
Forms("sfrmClientBuildContacts").Controls("txtBuildingNo").Value

If NewRecord Then 'When a new contact
is added assign next Contact Number for Building
If DCount("ContactNo", "tblClientBuildContacts", "[CustomerName]
= """ & Me![CustomerName] & """ AND [BuildingNo] = " & Me![BuildingNo]) = 0
Then
Me.txtContactNo = 1
Else
Me.txtContactNo = DMax("ContactNo", "tblCustomerContacts",
"[CustomerName] = """ & txtCustomerName & """ AND [BuildingNo] = " &
txtBuildingNo) + 1
End If
End If
End Sub

As you can see I've tried several things I've found in the discussion group
but Me.CustomerName and Me.BuildingNo is always blank. How do I use the
values that were captured is the first Open subroutine?
TIA
 
M

Marshall Barton

jim said:
Hi all, a pop-up form is opened from a subform with this code:

Private Sub Form_Open(Cancel As Integer)
Dim strCustomerName As String
Dim strBuildingNo As Long

If IsNull(OpenArgs) = False Then
Dim arrArgs() As String
arrArgs = Split(Me.OpenArgs, "~")
strCustomerName = arrArgs(0)
strBuildingNo = arrArgs(1)
End If
End Sub

It is working good and my array, arrArgs, is populating strCustomerName and
strBuildingNo perfectly. If a new record is needed I use the following:

Private Sub Form_BeforeUpdate(Cancel As Integer)
'Me!txtCustomerName.Value = Me!txtCustomerName.DefaultValue
'Me!CustomerName.Value =
Forms("sfrmClientBuildContacts").Controls("txtCustomerName").Value
' Me!BuildingNo.Value =
Forms("sfrmClientBuildContacts").Controls("txtBuildingNo").Value

If NewRecord Then 'When a new contact
is added assign next Contact Number for Building
If DCount("ContactNo", "tblClientBuildContacts", "[CustomerName]
= """ & Me![CustomerName] & """ AND [BuildingNo] = " & Me![BuildingNo]) = 0
Then
Me.txtContactNo = 1
Else
Me.txtContactNo = DMax("ContactNo", "tblCustomerContacts",
"[CustomerName] = """ & txtCustomerName & """ AND [BuildingNo] = " &
txtBuildingNo) + 1
End If
End If
End Sub

As you can see I've tried several things I've found in the discussion group
but Me.CustomerName and Me.BuildingNo is always blank. How do I use the
values that were captured is the first Open subroutine?


You are putting the values from OpenArgs in local variables.
If you want them to persist after the Open event runs, then
you need to put them in a place that retains the value (e.g.
(hidden?) form text boxes or module level variaibles).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top