Solved

Passing parameters using StLinkCriteria and OpenArgs

Posted on 2007-12-05
9
1,166 Views
Last Modified: 2013-11-28
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
0
Comment
Question by:MikeLong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 29

Expert Comment

by:Badotz
ID: 20416307
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?
0
 

Author Comment

by:MikeLong
ID: 20416543
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   ???
0
 
LVL 29

Expert Comment

by:Badotz
ID: 20416626
Ya lost me...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 61

Accepted Solution

by:
mbizup earned 150 total points
ID: 20416711
>Why is stLinkCrteria usually set to a command rather than to a value?

stLinkCriteria is set to a string value, literally "[SerialNo] = 123"  (as a whole).  

This string defines the criteria for the recordsource of the form you are opening (in other words, the WHERE clause of a SQL statement, with the "Where" omitted).

To open a form to an existing record where [SerialNo] = 123:

stLinkCriteria = "[SerialNo] = 123"  
DoCmd.OpenForm "StudentInstrument", , ,stLinkCriteria

To open a form to add a new record, and prefill the field:

DoCmd.OpenForm "StudentInstrument", , , , acFormAdd
Forms!StudentInstrument.SerialNo = 123


0
 
LVL 44

Expert Comment

by:GRayL
ID: 20416903
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.  
0
 

Author Closing Comment

by:MikeLong
ID: 31413047
Thank you, bmizup. Exactly what I was asking.
0
 

Author Comment

by:MikeLong
ID: 20417019
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.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 20417035
So, what was the point?
0
 

Author Comment

by:MikeLong
ID: 20424245
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".
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question