OpenArgs Problem

damian

Registered User.
Local time
Today, 13:16
Joined
Jun 27, 2004
Messages
87
I'm working in Access 2000. I have a continuous form "SecondarySupplierForm" that is opened from command buttons in individual records in several other forms. When a user clicks the button, "SecondarySupplierForm" opens, filtered to show just the records related to the 'SupplierNumber' of the record it was opened from.

I want the SecondarySupplierForm to auto-populate the SupplierNumber in a new record if the form is opened through a command button on another form.

Decided to go down the OpenArgs route and set the default value of new records using code below. Works great with numbers but if there are letters in the 'SupplierNumber' it simply puts '#Name?' in the new record field.

Any ideas?


Private Sub Command60_Click()
On Error GoTo Err_Command60_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "SecondarySupplierForm"


stLinkCriteria = "[SupplierNumber]=" & "'" & Me![SupplierNumber] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , OpenArgs:=Me.SupplierNumber

Exit_Command60_Click:
Exit Sub

Err_Command60_Click:
MsgBox Err.Description
Resume Exit_Command60_Click

End Sub

Following code is in 'SecondarySupplierForm' OpenEvent:

Private Sub Form_Open(Cancel As Integer)
If Not IsNull(Me.OpenArgs) Then
Me.SupplierNumber.DefaultValue = "=" & con_Quote & Me.OpenArgs & con_Quote
End If
End Sub
 
Have you tried using the OnLoad event of the next form rather than the Open event? The Open event is too early in the opening process to refer to controls on the form.
 

Users who are viewing this thread

Back
Top Bottom