Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Passing parameters using StLinkCriteria and OpenArgs

Posted on 2007-12-05
9
Medium Priority
?
1,188 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 61

Accepted Solution

by:
mbizup earned 600 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

636 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