Link to home
Start Free TrialLog in
Avatar of MikeLong
MikeLongFlag for New Zealand

asked on

Passing parameters using StLinkCriteria and OpenArgs

If I try this for a "Click" on the Instrument form:

    stLinkCriteria = "Me![SerialNo]"
    DoCmd.OpenForm "StudentInstrument", , , , acFormAdd, , stLinkCriteria

Then, in StudentInstrument| "Load" Procedure I say
    [SerialNo] = Me!OpenArgs

my form is magically pre-filled with the correct instrument Serial Number, I ask for the StudentID and proceed to do all the stuff I need to do to assign a Student to this instrument - just what I want - Except:

1. This does NOT seem to be the way it's supposed to work. When I see examples, people create a COMMAND in stLinkCriteria (with the judicious use of double and single quotes) they make stLinkCriteria to equal "[SerialNo] = 'inst123'" instead of just making it equal "inst123". Why? How is this command processed by the called form?
2. That's what I want to do. From the Student form I want to click "Rent an instrument", go to that same form, pre-fill StudentID, ask for an Instrument, and do the stuff. In order to do this I need stLinkCriteria (which is the same thing as OpenArgs, right?) to equal either, "[SerialNo] = 'inst123'" or "[StudentID] = 'stu456'"
Yours Stupidly
Avatar of Badotz
Badotz
Flag of United States of America image

1. Numeric fields do not need to be enclosed in apostrophes - string fields do. A string field containing an apostrophe, e.g., "o'Connell", must escape the apostrophe like this: "O_'_'_C_o_n_n_e_l" (the underscores are for clarity). If you use the Command object, then it will take care of this nonsense for you, but it requires more work on your part (instantiating, setting, establishing values, etc.).

2. Not sure what you mean here - can you clarify, please?
Avatar of MikeLong

ASKER

Getting a parameter to pass as I want it to look isn't the problem. The MAIN question is:

         Why is stLinkCrteria usually set to a command rather than to a value? I've found no examples in the receiving form as to how this command is executed. E.G. if, in the calling form, stLinkCriteria is set to "[SerialNo] = 123" (please ignore how this is accomplished), how, in the receiving form is the field, [SerialNo] actually set to the value 123   ???
Ya lost me...
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It all depends on the data type of the field you are using ins strLinkCriteria.  If it is numeric - no quotes, if it is text, you need them.  Nothing to do with 'people' - all to to with the way VBA parses the code.  If the field is numeric and you use quotes - bomb!  Likewise with the reverse.  
Thank you, bmizup. Exactly what I was asking.
As a general principle, the ONLY time I define a field as numeric, whether or not it may happen (currently) to contain all numeric digits, is when I may wish to do math using it. Serial numbers and the like are, to me, always text if I play any part in that decision.
So, what was the point?
Not a lot, really. It's just that, in all the research I did before asking the question, the problems with stLinkCriteria have ALWAYS to do with how many of what kind of quotes are required for text vs numeric fields. That was NOT my problem (as some contributors automatically thought). One main reason I don't have this problem is that I never define key fields (which may HAPPEN to be numbers) as "numeric".