passing values with openargs

buratti

Registered User.
Local time
Today, 10:32
Joined
Jul 8, 2009
Messages
234
Is there any way to determine the value type of an openargs value being passed, and then assign the value to the appropriate field depending on its value?

Example:
The onOpen even of my customer details from is now set to assign the openargs value (if any) to the Account Number field. What I want it to do is, if the openargs value is “numeric” (a 4 or 5 digit number only) then assign its value to account number field, but if it is a “text” value (customer name lets say) then assign its value to the Customer name field.

If that is even possible, I would need to go one step further and somehow distinguish the difference between a customer name value (text only) and the value of an address (mixed numbers and text) to pass the value to the correct field.

Was thinking something along the line of: (pretty sure these functions doesn't exist)

if openargs.datatype = "text only" then
me.customer_name = openargs
ElseIf openarge.datatype = "numeric value only" then
me.account_number = openargs
Elseif openargs.datatype = “numeric and text Value" then
me.Address = openargs
End If

Anyone have correct syntax for this or any other suggestions?
 
OpenArgs is a TEXT STRING only. So, whatever you pass you may need to convert to the datatype you need at the time you need it.
 
You can pass mutiple values in a single string by delimiting the string and then parsing it out when the form opens
Code:
docmd.openform frm, openargs:=data1 & "|" & data2 & "|" & data3
and when the form opens ....
Code:
dim args as variant
if not nz(me.openargs, "") = "" then 
  args = split(me.openargs, "|")
else
  err.raise 5, me.name
end if

dim i as integer
for i = 0 to ubound(args)
  debug.print args(i),
next

- Also, to determine datatypes VBA offers you functions like IsNumeric(), IsDate(), IsObject(), which return boolean values.
- There is also a VBA.Typename() function which returns the string name of the variable or object.
Cheers,
 
You can pass mutiple values in a single string by delimiting the string and then parsing it out when the form opens


Thanks I think this is what I would need, but i don't quite understand it. Would you be able to correct my errors check if my descriptions are correct and fill in any blanks below:

Code on control to open Customer detais form:
Code:
DoCmd.OpenForm "Customer Details", , , , , , OpenArgs:=Me.Account_Number & "|" & Me.Full_Name & "|" & Me.Address
code in onOpen event of Customer Details form:
Code:
[COLOR=black][FONT=Verdana]dim args as variant[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]if not nz(me.openargs, "") = "" then [FONT=Verdana][COLOR=lime]'if openargs contains anything then...[/COLOR][/FONT]
[/FONT][/COLOR][COLOR=black][FONT=Verdana] args = split(me.openargs, "|") [FONT=Verdana][COLOR=lime]'unsure what this does... splits openargs into an args array???[/COLOR][/FONT]
[/FONT][/COLOR][COLOR=black][FONT=Verdana]else[/FONT][/COLOR]
[COLOR=black][FONT=Verdana] err.raise 5, me.name [FONT=Verdana][COLOR=red]'What does this do?[/COLOR][/FONT]
[/FONT][/COLOR][COLOR=black][FONT=Verdana]end if[/FONT][/COLOR]
 
[COLOR=black][FONT=Verdana]dim i as integer[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]for i = 0 to ubound(args) [FONT=Verdana][COLOR=red]'what does this do?[/COLOR][/FONT][/FONT][/COLOR]
[COLOR=black][FONT=Verdana] debug.print args(i), [COLOR=#ff0000]'what does this do?[/COLOR][/FONT][/COLOR]
[COLOR=black][FONT=Verdana]next[/FONT][/COLOR]
[FONT=Verdana][COLOR=red]'where would I put...[/COLOR][/FONT]
[FONT=Verdana][COLOR=red]'me.account number = args(?)[/COLOR][/FONT]
[FONT=Verdana][COLOR=red]'me.fullname = args(?)[/COLOR][/FONT]
[COLOR=black][FONT=Verdana][COLOR=red]'me.address = args([/COLOR][COLOR=red]?)[/COLOR][/FONT][/COLOR]

Basically in short, how would I assign the correct array value to the appropriate field?
 
Step through the code. See what it does.
 

Users who are viewing this thread

Back
Top Bottom