Solved

Passing parameters using StLinkCriteria and OpenArgs

Posted on 2007-12-05
9
1,144 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
  • 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
 
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access 2007 Count Unique Values in a Group 5 35
is there a opposite on ON CURRENT in ms/access 15 34
Create Form using Wizard 14 39
Access 2010 Query Syntax 5 25
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now