A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Incomprehensible OpenArgs behavior



 
 
Thread Tools Display Modes
  #1  
Old November 10th, 2009, 07:07 PM posted to microsoft.public.access.forms
night_writer
external usenet poster
 
Posts: 12
Default Incomprehensible OpenArgs behavior

Incomplrehensible to me, at least. I'm hoping wiser heads will offer
advice.

I have a form (frmCirculars) that displays individual records of
correspondence (circulars) in single form view. If the form opens
directly, you can cycle through all 13,000 or so records. Each
circular is associated with a project.

I have a project form (frmProjects) that displays all related
circulars in abbreviated fashion on a subform. For any particular
circular on the subform, there is a "view" button that opens a Single
Form view of the associated circular. I would also like to be able to
add a new circular to a project by opening the main circular form in
add mode, and I would like to pass the project number from frmProjects
to the newly opened frmCirculars.

To that end, I have added a button (btnAddNewCircular) to the
frmProjects subform and tried to pass the ProjectID to the new form.
ProjectID is a long integer. Here is my code:

Dim stDocName As String, lngOpenArgs As Long
stDocName = "frmCirculars"
lngOpenArgs = Me.Parent!ProjectID
DoCmd.OpenForm stDocName, , , , acFormAdd, , lngOpenArgs

I've got two problems. The first time I click the button after opening
frmProjects, no opening arguement is passed. I have attached this code
to the Open event of the called form, and I invariably get "OOPS" (no
argument passed) on the first try:

If Not IsNull(Me.OpenArgs) Then
MsgBox "OK"
MsgBox Me.OpenArgs
Me.ProjectID = Me.OpenArgs ' You can't assign a value to this
object
MsgBox Me.ProjectID.Value
Else
MsgBox "OOPS"
End If

If I then close frmCircular and click the button on frmProjects again,
the argument does pass (MsgBox = "OK") and it is the correct argument
(MsgBox Me.OpenArgs).

And here is my second problem. I can't figure out how to get the
opening arguement into the field I want (ProjectID). I get the error
"You can't assign a value to this object." I suppose it's possible
that the Me.ProjectID (which is the same field name in both the
calling and the opening form) might be messing things up, but I have
tried several ways of referencing the field, and nothing seems to
work.

I might also be going about this in the completely wrong way. The
example code in the help file all has to do with finding an existing
record, and all I want to do is put a value in a field of a new
record.

So, these are my two problems:
1. Why won't the OpenArgs pass to the opening form the first time, but
will pass the second time, and
2. How do I need to reference the frmCirculars ProjectID field so it
can be updated with the OpenArgs info

Any help would be greatly appreciated.
  #2  
Old November 10th, 2009, 07:31 PM posted to microsoft.public.access.forms
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default Incomprehensible OpenArgs behavior

"night_writer" wrote in message
...
Incomplrehensible to me, at least. I'm hoping wiser heads will offer
advice.

I have a form (frmCirculars) that displays individual records of
correspondence (circulars) in single form view. If the form opens
directly, you can cycle through all 13,000 or so records. Each
circular is associated with a project.

I have a project form (frmProjects) that displays all related
circulars in abbreviated fashion on a subform. For any particular
circular on the subform, there is a "view" button that opens a Single
Form view of the associated circular. I would also like to be able to
add a new circular to a project by opening the main circular form in
add mode, and I would like to pass the project number from frmProjects
to the newly opened frmCirculars.

To that end, I have added a button (btnAddNewCircular) to the
frmProjects subform and tried to pass the ProjectID to the new form.
ProjectID is a long integer. Here is my code:

Dim stDocName As String, lngOpenArgs As Long
stDocName = "frmCirculars"
lngOpenArgs = Me.Parent!ProjectID
DoCmd.OpenForm stDocName, , , , acFormAdd, , lngOpenArgs

I've got two problems. The first time I click the button after opening
frmProjects, no opening arguement is passed. I have attached this code
to the Open event of the called form, and I invariably get "OOPS" (no
argument passed) on the first try:

If Not IsNull(Me.OpenArgs) Then
MsgBox "OK"
MsgBox Me.OpenArgs
Me.ProjectID = Me.OpenArgs ' You can't assign a value to this
object
MsgBox Me.ProjectID.Value
Else
MsgBox "OOPS"
End If

If I then close frmCircular and click the button on frmProjects again,
the argument does pass (MsgBox = "OK") and it is the correct argument
(MsgBox Me.OpenArgs).

And here is my second problem. I can't figure out how to get the
opening arguement into the field I want (ProjectID). I get the error
"You can't assign a value to this object." I suppose it's possible
that the Me.ProjectID (which is the same field name in both the
calling and the opening form) might be messing things up, but I have
tried several ways of referencing the field, and nothing seems to
work.

I might also be going about this in the completely wrong way. The
example code in the help file all has to do with finding an existing
record, and all I want to do is put a value in a field of a new
record.

So, these are my two problems:
1. Why won't the OpenArgs pass to the opening form the first time, but
will pass the second time, and



I'm not completely sure why you're not seeing the ProjectID in OpenArgs the
first time around, but I note that values passed via OpenArgs should be
strings. I'd expect the long integer value you're passing to be converted
automatically to a string, but maybe it will make a difference if you
explicitly convert it to a string:

DoCmd.OpenForm stDocName, _
DataMode:=acFormAdd, _
OpenArgs:=CStr(Me.Parent!ProjectID)

2. How do I need to reference the frmCirculars ProjectID field so it
can be updated with the OpenArgs info


You can't assign the value in the form's Open event, because the form's
recordsource hasn't even been queried yet. I think, though, that you should
be able to assign it in the form's Load event. Try this:

'------ start of suggested code ------
Private Sub Form_Load()

Dim strOpenArgs As String

strOpenArgs = Me.OpenArgs & vbNullString

If Len(strOpenArgs) 0 Then
MsgBox "OK - OpenArgs = " & strOpenArgs
Me.ProjectID = Clng(strOpenArgs)
Else
MsgBox "OOPS"
' NOTE: Assuming you want to use this form also
' for browsing & editing, you wouldn't really have the
' above line.
End If

End Sub

'------ end of suggested code ------


--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

  #3  
Old November 10th, 2009, 08:39 PM posted to microsoft.public.access.forms
night_writer
external usenet poster
 
Posts: 12
Default Incomprehensible OpenArgs behavior

On Nov 10, 12:31*pm, "Dirk Goldgar"
wrote:
"night_writer" wrote in message

...





Incomplrehensible to me, at least. I'm hoping wiser heads will offer
advice.


I have a form (frmCirculars) that displays individual records of
correspondence (circulars) in single form view. If the form opens
directly, you can cycle through all 13,000 or so records. Each
circular is associated with a project.


I have a project form (frmProjects) that displays all related
circulars in abbreviated fashion on a subform. For any particular
circular on the subform, there is a "view" button that opens a Single
Form view of the associated circular. I would also like to be able to
add a new circular to a project by opening the main circular form in
add mode, and I would like to pass the project number from frmProjects
to the newly opened frmCirculars.


To that end, I have added a button (btnAddNewCircular) to the
frmProjects subform and tried to pass the ProjectID to the new form.
ProjectID is a long integer. Here is my code:


* *Dim stDocName As String, lngOpenArgs As Long
* *stDocName = "frmCirculars"
* *lngOpenArgs = Me.Parent!ProjectID
* *DoCmd.OpenForm stDocName, , , , acFormAdd, , lngOpenArgs


I've got two problems. The first time I click the button after opening
frmProjects, no opening arguement is passed. I have attached this code
to the Open event of the called form, and I invariably get "OOPS" (no
argument passed) on the first try:


If Not IsNull(Me.OpenArgs) Then
* *MsgBox "OK"
* *MsgBox Me.OpenArgs
* *Me.ProjectID = Me.OpenArgs ' You can't assign a value to this
object
* *MsgBox Me.ProjectID.Value
Else
* *MsgBox "OOPS"
End If


If I then close frmCircular and click the button on frmProjects again,
the argument does pass (MsgBox = "OK") and it is the correct argument
(MsgBox Me.OpenArgs).


And here is my second problem. I can't figure out how to get the
opening arguement into the field I want (ProjectID). I get the error
"You can't assign a value to this object." I suppose it's possible
that the Me.ProjectID (which is the same field name in both the
calling and the opening form) might be messing things up, but I have
tried several ways of referencing the field, and nothing seems to
work.


I might also be going about this in the completely wrong way. The
example code in the help file all has to do with finding an existing
record, and all I want to do is put a value in a field of a new
record.


So, these are my two problems:
1. Why won't the OpenArgs pass to the opening form the first time, but
will pass the second time, and


I'm not completely sure why you're not seeing the ProjectID in OpenArgs the
first time around, but I note that values passed via OpenArgs should be
strings. *I'd expect the long integer value you're passing to be converted
automatically to a string, but maybe it will make a difference if you
explicitly convert it to a string:

* * DoCmd.OpenForm stDocName, _
* * * * DataMode:=acFormAdd, _
* * * * OpenArgs:=CStr(Me.Parent!ProjectID)

2. How do I need to reference the frmCirculars ProjectID field so it
can be updated with the OpenArgs info


You can't assign the value in the form's Open event, because the form's
recordsource hasn't even been queried yet. *I think, though, that you should
be able to assign it in the form's Load event. *Try this:

'------ start of suggested code ------
Private Sub Form_Load()

* * Dim strOpenArgs As String

* * strOpenArgs = Me.OpenArgs & vbNullString

* * If Len(strOpenArgs) 0 Then
* * * * MsgBox "OK - OpenArgs = " & strOpenArgs
* * * * Me.ProjectID = Clng(strOpenArgs)
* * Else
* * * * MsgBox "OOPS"
* * * * ' NOTE: Assuming you want to use this form also
* * * * ' for browsing & editing, you wouldn't really have the
* * * * ' above line.
* * End If

End Sub

'------ end of suggested code ------

--
Dirk Goldgar, MS Access MVP
Access tips:www.datagnostics.com/tips.html

(please reply to the newsgroup)- Hide quoted text -

- Show quoted text -


Thank you so much! Your fixes solved both of my problems!

Alice
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:39 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.