Passing A Value to Another Form

Cydee

New member
Local time
Today, 21:55
Joined
Feb 22, 2021
Messages
5
Hi All,

I have a main form which is filled in and then I have added a button to move on to a second form. I wanted the ID from this first form to pass in to the second form as it opens.

I have used VBA to do this using OpenArgs as below:
For the button

Private Sub Command25_Click() DoCmd.OpenForm "Main", WhereCondition:="[Forms].[Main].[ID]=" & Me![Review_ID], WindowMode:=acDialog, OpenArgs:=Me.[Review_ID] End Sub

and then as the form Main loads
Private Sub Form_Load() If Me.OpenArgs <> "" Then Me![ID].DefaultValue = "" & Me.[OpenArgs] & "" End If End Sub

This seems to be working well as it is passing a value through the problem is how the string is being read.
The ID is of the form "001", but the value that is being read into the second form is "1".

Both of the ID fields are short text and I know that OpenArgs is picking up a string so I thought it should be okay.

Does anyone have any advice on how to make sure the string is not represented as numeric?

Thanks,
Cydney
 
I would recommend you change them to Autonumbers so that they are actually numeric in the first place.
 
Try
Code:
Me![ID].DefaultValue = '" & Me.[OpenArgs] & "'"

otherwise use Format() to your liking?
 
Thank you very much, the edit to the code worked perfectly! :)
While it might have done, I would take on Isaac's advice and just make the IDs, autonumber
 
it doesn't matter whether your details are numbers or strings, but you need to be consistent.
"001" is a string
1 s a number

If you convert "001" to a number, you will get 1, not 001

Openargs are strings, not numbers, so using this will set Default Value to whatever the openargs string is,

Me![ID].DefaultValue = '" & Me.[OpenArgs] & "'"
 

Users who are viewing this thread

Back
Top Bottom