By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,339 Members | 1,973 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,339 IT Pros & Developers. It's quick & easy.

Need Help opening a form from a form, using Openargs

P: n/a
Using code and suggestions from an earkier thread in this group, I have
created the following cond for the open event of a form I am opening from
the button click event of another form.
Private Sub Form_Open(Cancel As Integer)

If Len(Me.OpenArgs & "") > 0 Then
Dim i As Integer
Dim s As String
s = CStr(Me.OpenArgs)
i = InStr(1, s, "%")
Debug.Print Me.OpenArgs & " " & i
Me.InvoiceNumber = Left$(s, i - 1)
Me.CustomerID = Mid$(s, i + 1)
Me.CHECK_NUMBER.SetFocus
End If
End Sub
The lines assigning values to controls on the opened form raise an error
which states that "you cannot assign a value to this object"

My goal is to open the new form and assign values to controls, based on the
original form, and to create a new record.

The calling button contains the following code for the Click event.
Private Sub Command15_Click()
On Error GoTo ErrorHandler

Dim stDocName As String
Dim strargs As String

strargs = Me.InvoiceNumber & "%" & Me.CustomerID
stDocName = "frmSalesEntry"
DoCmd.OpenForm stDocName, acNormal, , , acFormEdit, , strargs
Debug.Print strargs
ErrorHandlerExit:
Exit Sub

ErrorHandler:
MsgBox "Error No: " & Err.number & "; Description: " & _
Err.Description
Resume ErrorHandlerExit

End Sub

What am I doing wrong?

tia,

Any help is much appreciated.

Jim Evans
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You must do this in th Load event of the Form. You cannot assign values in
the Open event.

Darryl Kerkeslager
"Jim Evans" <ji*@microsoftdiscussions.com> wrote in message
news:11*************@corp.supernews.com...
Using code and suggestions from an earkier thread in this group, I have
created the following cond for the open event of a form I am opening from
the button click event of another form.
Private Sub Form_Open(Cancel As Integer)

If Len(Me.OpenArgs & "") > 0 Then
Dim i As Integer
Dim s As String
s = CStr(Me.OpenArgs)
i = InStr(1, s, "%")
Debug.Print Me.OpenArgs & " " & i
Me.InvoiceNumber = Left$(s, i - 1)
Me.CustomerID = Mid$(s, i + 1)
Me.CHECK_NUMBER.SetFocus
End If
End Sub
The lines assigning values to controls on the opened form raise an error
which states that "you cannot assign a value to this object"

My goal is to open the new form and assign values to controls, based on the original form, and to create a new record.

The calling button contains the following code for the Click event.
Private Sub Command15_Click()
On Error GoTo ErrorHandler

Dim stDocName As String
Dim strargs As String

strargs = Me.InvoiceNumber & "%" & Me.CustomerID
stDocName = "frmSalesEntry"
DoCmd.OpenForm stDocName, acNormal, , , acFormEdit, , strargs
Debug.Print strargs
ErrorHandlerExit:
Exit Sub

ErrorHandler:
MsgBox "Error No: " & Err.number & "; Description: " & _
Err.Description
Resume ErrorHandlerExit

End Sub

What am I doing wrong?

tia,

Any help is much appreciated.

Jim Evans

Nov 13 '05 #2

P: n/a
Darryl,

Your comment and changing the open: datamode to acformadd gives me exactly
what I need.

Thanks much for your help

btw, I believe you wrote much of the code for the thread I used as a
starter!.

Jim Evans
"Darryl Kerkeslager" <Ke*********@comcast.net> wrote in message
news:vv********************@comcast.com...
You must do this in th Load event of the Form. You cannot assign values in the Open event.

Darryl Kerkeslager
"Jim Evans" <ji*@microsoftdiscussions.com> wrote in message
news:11*************@corp.supernews.com...
Using code and suggestions from an earkier thread in this group, I have
created the following cond for the open event of a form I am opening from the button click event of another form.
Private Sub Form_Open(Cancel As Integer)

If Len(Me.OpenArgs & "") > 0 Then
Dim i As Integer
Dim s As String
s = CStr(Me.OpenArgs)
i = InStr(1, s, "%")
Debug.Print Me.OpenArgs & " " & i
Me.InvoiceNumber = Left$(s, i - 1)
Me.CustomerID = Mid$(s, i + 1)
Me.CHECK_NUMBER.SetFocus
End If
End Sub
The lines assigning values to controls on the opened form raise an error
which states that "you cannot assign a value to this object"

My goal is to open the new form and assign values to controls, based on

the
original form, and to create a new record.

The calling button contains the following code for the Click event.
Private Sub Command15_Click()
On Error GoTo ErrorHandler

Dim stDocName As String
Dim strargs As String

strargs = Me.InvoiceNumber & "%" & Me.CustomerID
stDocName = "frmSalesEntry"
DoCmd.OpenForm stDocName, acNormal, , , acFormEdit, , strargs
Debug.Print strargs
ErrorHandlerExit:
Exit Sub

ErrorHandler:
MsgBox "Error No: " & Err.number & "; Description: " & _
Err.Description
Resume ErrorHandlerExit

End Sub

What am I doing wrong?

tia,

Any help is much appreciated.

Jim Evans


Nov 13 '05 #3

P: n/a
I believe the problem is that you're trying to execute the code too early in
the form open process. The code may work if you put it in the Load event
handler rather than Open.

Also, if you don't mind some unsolicited code style suggestions...

- You should either give your variables self-descriptive names or commend the
Dim lines.
- Splitting a string based on a delimiter is a common need, so the code for
that should be in its own reusable function. Actually, Access already has one
you can use called Split.
- It's a good idea to split the event response code from the response action
code, so that the event handler just calls one or a few worker procedures that
are self-descriptively named.

Private Sub Form_Load()
If IsOpenForNewInvc() Then
ParseFieldsFromOpenArgs
InitNewInvcUiState
End If
End Sub

Private Function IsOpenForNewInvc() As Boolean
IsOpenForNewInvc = (Len(OpenArgs) > 0)
End Function

Private Sub ParseFieldsFromOpenArgs()
Const clngInvoiceNumIndx = 0&
Const clngCustomerIdIndx = 1&
Dim varArgs As Variant

varArgs = Split(OpenArgs, "%")
Me!InvoiceNumber = varArgs(clngInvoiceNumIndx)
Me!CustomerID = varArgs(clngCustomerIdIndx)

End Sub

Private Sub InitNewInvcUiState
Me!CHECK_NUMBER.SetFocus
End Sub
On Wed, 2 Feb 2005 21:23:07 -0500, "Jim Evans" <ji*@microsoftdiscussions.com>
wrote:
Using code and suggestions from an earkier thread in this group, I have
created the following cond for the open event of a form I am opening from
the button click event of another form.
Private Sub Form_Open(Cancel As Integer)

If Len(Me.OpenArgs & "") > 0 Then
Dim i As Integer
Dim s As String
s = CStr(Me.OpenArgs)
i = InStr(1, s, "%")
Debug.Print Me.OpenArgs & " " & i
Me.InvoiceNumber = Left$(s, i - 1)
Me.CustomerID = Mid$(s, i + 1)
Me.CHECK_NUMBER.SetFocus
End If
End Sub
The lines assigning values to controls on the opened form raise an error
which states that "you cannot assign a value to this object"

My goal is to open the new form and assign values to controls, based on the
original form, and to create a new record.

The calling button contains the following code for the Click event.
Private Sub Command15_Click()
On Error GoTo ErrorHandler

Dim stDocName As String
Dim strargs As String

strargs = Me.InvoiceNumber & "%" & Me.CustomerID
stDocName = "frmSalesEntry"
DoCmd.OpenForm stDocName, acNormal, , , acFormEdit, , strargs
Debug.Print strargs
ErrorHandlerExit:
Exit Sub

ErrorHandler:
MsgBox "Error No: " & Err.number & "; Description: " & _
Err.Description
Resume ErrorHandlerExit

End Sub

What am I doing wrong?

tia,

Any help is much appreciated.

Jim Evans


Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.