Passing Multiple OpenArgs (1 Viewer)

Lynn_AccessUser

Registered User.
Local time
Today, 07:59
Joined
Feb 4, 2003
Messages
125
Is there any way to pass multiple OpenArgs.

I have a form that opens 2 different ways depending on what arguement is passed. However, I also need to pass the primary key from one form to another.
 
I've passed several arguments to a form through its openargs. What I do is before I open the form I create a string variable that combines all the arguments I want to pass with a semi-colon in between each one. I chose semi-colon not for any particular reason. Any symbol will be fine as long as it's not a part of the argument.

Then to break them up requires a little bit of coding to step through each character in the open args and take what's in between each of the symbols that you choose.

Following?
 
Talk about resurecting this thread from the dead!

But would anyone be able to give an example of this?

I was looking around on some other forums and found the following:

In the FIRST form declare a public function:

Public Function ParseText(TextIn As String, x) As Variant
On Error Resume Next
Dim Var As Variant
Var = Split(TextIn, "|", -1)
ParseText = Var(x)

End Function


Then Pass the openarg data:

Private Sub BtnContinue_over_Click()

Dim stDocName As String
Dim stLink1 As String
Dim stLink2 As String
Dim stLink3 As String

stLink1 = Me.Contracts_CustomerName
stLink2 = Me.Contracts_ContractStatus
stLink3 = Me.Contracts_ContractNum

stDocName = "Quotes"
DoCmd.OpenForm stDocName, , , , , , "stLink1|stLink2|stLink3"
DoCmd.Close acForm, "Contracts"
DoCmd.GoToRecord , , acNewRec


In the FORM_LOAD event of the SECOND form use:

If Not IsNull(Me.OpenArgs) Then
Dim strA As String
Dim strB As String
Dim strC As String

strA = ParseText(OpenArgs, 0)
strB = ParseText(OpenArgs, 1)
strC = ParseText(OpenArgs, 2)

MsgBox "The OpenArgs are:" & vbNewLine & strA & " " & strB &
vbNewLine & strC & " " & strD


I tried using this and it keeps saying "Compile Error: Sub or Function not Defined" and it highlights 'ParseText'

I'm guessing its the public function thats not really working? or is that code bad? help please! :)
 
If you want to use that function from other forms, you should put it in a standard module rather than a form module.
 
Can someone tell me how openargs are any better than passing a public variable? Seem to me that using a public variable would be less error prone and easier than putting all arguments into one long string and spllitting it again?
 
it seems easier but at the same time using OpenArgs limits those variables to that set of forms

say you have a Contacts form and a Contracts form

And you want to select a contact in form1 and have that contact pre-selected in form2 by using DoCmd.OpenForm, all you gotta do is put <fieldname> in the openargs argument.... and its passed!

DoCmd.OpenForm(FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs)

if you want to use OpenArgs, but nothing else just put ,'s in place so for example if fieldname was 'contactname' I would type:

DoCmd.OpenForm Formname, , , , , , Contactname

See how in the order above, the OpenArgs argument is in the last comma space, well you enter the data you want to pass through openargs in that space. Fieldname, defined variable, constant, whatever you want!

That would be in form1 in a Button_Click event or something, then in form 2 you refer to the data passed from form 1 as Me.OpenArgs

You could do, in form 2.

MsgBox Me.OpenArgs and it will display what data was passed from Form 1 to Form 2.

I see the advantage to this as its not a global variable, its a little more secure and specific to these forms only!
 
How would OpenArgs be any more secure than a public variable? One could simply set the variable to null or empty strings, depending how it's declared. Besides, if anyone could go to VBE, you've got more bigger problems.

Furthermore, while OpenArgs may be specific to a form, it's simply a string. With public variables, you can ensure that correct data types are entered, and there's more consistency in your codes especially if you are using similar openargs for various forms.
 
I agree with Banana! I use global (Public) variables all the time, without any problem! You should always set them to zero or a zero length string when you're done with them, but other than that they're very easy to use. From time to time I see "gurus" stating that they don't like the practise of using them, but when questioned, I've never had one give me a cogent argument against them!

Linq
 
well I am definately by no means a guru, definately a newbie at VB but this is definately a HUGE learning experience for me!

I was told BY the gurus at work that global variables are bad, and they said something that didnt make sense to me at the time. I'm sorry, I can't recite what they said. That being said, how would I set a global variable and set it to a zero or zero length string after being done with it?

Like, say I had fieldname1 and fieldname2 in form1 and wanted to pass the value of fieldname1 to fieldnameA and fieldname2 to fieldnameB which are in form2

How would I go about doing that, then declare the values to zero or zero length strings??? (Explicit examples for the newbie please? :))
 
I prefer to avoid Global variables in favor of OpenArgs because it is easier to understand and maintain by someone else years later. All of the information is contained in just the two class modules instead of having to include a third standard module. Hopefully just looking at the OpenForm code and the OnLoad event of the next form is all it takes. Just my $0.02.
 
Last edited:
How would I go about doing that, then declare the values to zero or zero length strings??? (Explicit examples for the newbie please? :))
I have a module called GlobalVariables. One of the subroutines is DatabaseColors.

Code:
Public MSG1 As String
Public MSG2 As String
Public TITLE As String
Rem Global Variables to Pass Values From One Form to Another
Public FormNamestr As String
Public TextNamestr As String
Public Blackclr As Long
Public Whiteclr As Long
Public Greyclr As Long
Public Purpleclr As Long
Public Greenclr As Long
Public Redclr As Long
Public Borderclr As Long
Public Tempclr As Long
Public FormBackclr As Long

Public Sub DatabaseColors()
    Rem standard color assignments    
    Blackclr = 0
    Whiteclr = 16777215
    Greyclr = 13882323
    Redclr = 255
    Purpleclr = 13451722
    Greenclr = 11323658
    Borderclr = 4796088
    FormBackclr = 6076672
End Sub

When I open the first form in the database, the OnLoad event has the following code.
Code:
Call DataBaseColors

In this example, the values are meant to be static, but they don't have to be. They can be changed. MSG1 is the string for MSGBOX and FormNamestr is used to pass the name of the underlying form to the new form. This can also be done with OpenArgs.
 

Users who are viewing this thread

Back
Top Bottom