Opening a new linked form gives #Name error (1 Viewer)

Lanser

Registered User.
Local time
Today, 06:07
Joined
Apr 5, 2010
Messages
60
I have a main form with a reference number(DocRef) NOT the record ID

I set a command button to open a new form to add to a table linked to the main table but I can't get the Reference to come across I just get a #Name? error and unless I manually enter the DocRef it just creates a blank entry I have tried using a Where statement instead of OpenArgs but that just leaves the reference box blank

On Documents Form
Code:
Private Sub New_Version_Click()
DoCmd.OpenForm "NewVerForm", DataMode:=acFormAdd, WindowMode:=acDialog, OpenArgs:=Me.DocRef
End Sub

and New Version Form
Code:
Private Sub Form_Open(Cancel As Integer)
Me.DocRef.DefaultValue = Me.OpenArgs
End Sub
 

Attachments

  • accessform.JPG
    accessform.JPG
    62.7 KB · Views: 46

missinglinq

AWF VIP
Local time
Today, 01:07
Joined
Jun 20, 2003
Messages
6,423
In the secondary Form, try moving your code to the Form_Load event, instead of the Form_Open event. Generally speaking...Form_Open is to early to try doing any type of data manipulation.

Linq ;0)>
 

Lanser

Registered User.
Local time
Today, 06:07
Joined
Apr 5, 2010
Messages
60
Moving the code to on Load made no difference.

With a bit of playing using MsgBox it appears that a Null value is being passed to the new form even though the correct DocRef value is found

Using MsgBox in the on load gives an invalid use of null and on the Click OpenArgs tooltip is Null but Me.DocRef is showing correct value


Sorry again added the wrong test db
 

Attachments

  • Document Control_old.accdb
    1.9 MB · Views: 49
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:07
Joined
Oct 29, 2018
Messages
21,467
Moving the code to on Load made no difference.

With a bit of playing using MsgBox it appears that a Null value is being passed to the new form even though the correct DocRef value is found

Using MsgBox in the on load gives an invalid use of null and on the Click OpenArgs tooltip is Null but Me.DocRef is showing correct value
Hi. It's kind of hard to test your db without the data file. Which form are we supposed to check?
 

Lanser

Registered User.
Local time
Today, 06:07
Joined
Apr 5, 2010
Messages
60
Opps sorry its on the Main Document Form (DocForm) on the switchboard, and the New Version form (NewVerForm) is triggered by the New Version button as the image in my first post
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 06:07
Joined
Sep 12, 2006
Messages
15,652
does this work?

Me.DocRef.DefaultValue = Me.OpenArgs

perhaps it needs to be in the current event.

Code:
if me.newrecord then 
    Me.DocRef.DefaultValue = Me.OpenArgs
end if

note that openargs is a string,

-----
[edit]

also, maybe the call should be ! not .

OpenArgs:=Me!DocRef
 

Lanser

Registered User.
Local time
Today, 06:07
Joined
Apr 5, 2010
Messages
60
Thanks for the quick response, but no that makes no difference
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:07
Joined
Sep 21, 2011
Messages
14,265
Well I initially had Null as well, but now I get the value,no idea why. I did change the call to just positional parameters, but now back to your keyword version, but still #Name on form.?

Msgbox on form open


 

Attachments

  • Openargs.PNG
    Openargs.PNG
    26.6 KB · Views: 299
  • newver.PNG
    newver.PNG
    10.6 KB · Views: 253

Gasman

Enthusiastic Amateur
Local time
Today, 06:07
Joined
Sep 21, 2011
Messages
14,265
I have a workaround, providing you can get the value into the form as OpenArgs.

Put this code in the Load event

Code:
Me.DocRef = Me.OpenArgs

HTH
 

Lanser

Registered User.
Local time
Today, 06:07
Joined
Apr 5, 2010
Messages
60
Well that works so far, as simple as taking out the .DefaultValue its finally getting near useable for me anyways :)

Thanks a lot for your help
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:07
Joined
Sep 21, 2011
Messages
14,265
If you think about it, you do not need a default value as it is likely to change all the time.?
 

Micron

AWF VIP
Local time
Today, 01:07
Joined
Oct 20, 2018
Messages
3,478
The solution is hidden in post 8 comment. Maybe if open args was passed to a string variable first, then use the variable; otherwise
"'" & Me.OpenArgs & "'"

EDIT -
No to variable - must wrap in quotes.
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 06:07
Joined
Sep 21, 2011
Messages
14,265
The solution is hidden in post 8 comment. Maybe if open args was passed to a string variable first, then use the variable; otherwise
"'" & Me.OpenArgs & "'"

Micron,
Why does it work for Me.DocRef then.?
Still not sure why I was receiving Null when I first downloaded the DB :confused:
 

Micron

AWF VIP
Local time
Today, 01:07
Joined
Oct 20, 2018
Messages
3,478
Micron,
Why does it work for Me.DocRef then.?
Not sure but my guess would be that the DefaultValue property data type is Variant seeing as how it can accept anything but auto number or OLE. Therefore, the OpenArgs value would have to be properly delimited to comply with the data type of the bound field because you're passing a variant to it. A text field is already defined as text data type, thus would accept OpenArgs being passed to its Value property (which is the default property for a textbox) as long as OpenArgs could be interpreted as text.

That's all just speculation on my part. I can find no info on the data type of the DefaultValue property.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:07
Joined
Oct 29, 2018
Messages
21,467

Attachments

  • default.PNG
    default.PNG
    94.1 KB · Views: 266

Gasman

Enthusiastic Amateur
Local time
Today, 06:07
Joined
Sep 21, 2011
Messages
14,265
Nice one theDBguy,

The following works. However I'd still go with my method, just for a little less typing, but good to know about.

Code:
Private Sub Form_Open(Cancel As Integer)
Me.DocRef.DefaultValue = """ & Me.OpenArgs & """
MsgBox Me.OpenArgs

End Sub
 

Micron

AWF VIP
Local time
Today, 01:07
Joined
Oct 20, 2018
Messages
3,478
However I'd still go with my method...
Code:
Me.DocRef.DefaultValue = """ & Me.OpenArgs & """
Is that what you had? Upon reviewing your posts I can't find where you were using that otherwise I wouldn't have suggested it at such a late stage. Thanks dbg - it's there in web docs as well. I missed it.

So the explanation is that OpenArgs of text type have to be delimited same as if you were trying to pass a literal string to a control, such as "apple"?
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:07
Joined
Sep 21, 2011
Messages
14,265
Well that works so far, as simple as taking out the .DefaultValue its finally getting near useable for me anyways :)

Thanks a lot for your help

Just realised that is you wanted to add more than one record at a time, you would need defaultvalue?
 

Users who are viewing this thread

Top Bottom