Solved DoCmd.openform (Setting variable default value in destination form) (1 Viewer)

Jordonjd

Member
Local time
Today, 01:02
Joined
Jun 18, 2020
Messages
96
Hi there,
I have several forms (sales order, purchase order, invoice) that all use one "notes" form.
When i click a button on the origin form it opens the "notes" form and populates the "Tbl_Note_Parent_Ref" field with the reference from the origin form
but.. if the origin ref ([crm-1-ref]) is for example "1000-10" instead of populating the "Tbl_Note_Parent_Ref" with the text is calculates and inputs a result so.. "990"

Basically, click to popup the notes form, add the new note, when closed the origin form displays the new note in the note section

Here is the code i am using.

(Notes form)

Code:
Private Sub Form_Current()

   If Not IsNull(Me.OpenArgs) And Me.NewRecord Then

      Me.Tbl_Note_Parent_Ref.DefaultValue = Me.OpenArgs

   End If

End Sub

The code for the button on origin form (one fo 3 forms with similar code)
Code:
Private Sub Bttn_Add_New_Note_Click()


DoCmd.OpenForm "Frm_Note_Add_New", acNormal, , , acFormAdd, acDialog, [crm-1-ref]


Me.Refresh

End Sub

Im just interested to see if there is a way to utilising the origin field as text only without acces making a calculation of it.

Or if there is a simpler way to have several forms
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:02
Joined
Oct 29, 2018
Messages
21,447
Hi. Try it this way:
...
Me.Tbl_Note_Parent_Ref.DefaultValue = """" & Me.OpenArgs & """"
...

Hope that helps...
 

Micron

AWF VIP
Local time
Yesterday, 19:02
Joined
Oct 20, 2018
Messages
3,478
Im just interested to see if there is a way to utilising the origin field as text only without acces making a calculation of it.
IMO the best way is to not use special characters in object names. That [crm-1-ref] looks like a field reference. I had this happen to me many years ago when I didn't know better. Now you do too, I suspect. See

Naming conventions - http://access.mvps.org/access/general/gen0012.htm
https://www.access - programmers.co.uk/forums/showthread.php?t=225837

What not to use in names - http://allenbrowne.com/AppIssueBadWord.html
 

Gasman

Enthusiastic Amateur
Local time
Today, 00:02
Joined
Sep 21, 2011
Messages
14,218
What about using Cstr()?
 

June7

AWF VIP
Local time
Yesterday, 15:02
Joined
Mar 9, 2014
Messages
5,463
@Micron, issue is not with field name (although I agree it is a bad name), it's with the data.

OpenArgs is a variant type so it can hold any kind of data, including Null. CStr() will error on Null. If the field will never be Null, then CStr() should work.

However, I am not able to replicate issue. "1000-10" passes intact.
 
Last edited:

Micron

AWF VIP
Local time
Yesterday, 19:02
Joined
Oct 20, 2018
Messages
3,478
Im just interested to see if there is a way to utilising the origin field as text only without acces making a calculation of it.
@June7; I guess I took it that there must be something (perhaps fields or variables named crm and ref) and that a calculation was being performed when it shouldn't be. If you want to pass [crm-1-ref] to open args and that is a string, it ought to be "[crm-1-ref]" or perhaps "crm-1-ref". If that's totally off the mark, never mind because I'm going to switch from coffee (when I wrote my post) to wobbly pops, in which case I'll make even less sense. 🥴
 

Gasman

Enthusiastic Amateur
Local time
Today, 00:02
Joined
Sep 21, 2011
Messages
14,218
You mean as a way of getting around naming things properly?
No, by way of ensuring that Access sees the value as a string and not a formula?
 

Jordonjd

Member
Local time
Today, 01:02
Joined
Jun 18, 2020
Messages
96
I agree as well, sadly i have filled my DB with badly named objects and yes its a major pain sometimes

Thanks for the all replies :D
 

Users who are viewing this thread

Top Bottom