Solved

Passing parameters using StLinkCriteria and OpenArgs

Posted on 2007-12-05
9
1,138 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
Comment Utility
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
Comment Utility
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
Comment Utility
Ya lost me...
0
 
LVL 61

Accepted Solution

by:
mbizup earned 150 total points
Comment Utility
>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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 44

Expert Comment

by:GRayL
Comment Utility
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
Comment Utility
Thank you, bmizup. Exactly what I was asking.
0
 

Author Comment

by:MikeLong
Comment Utility
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
Comment Utility
So, what was the point?
0
 

Author Comment

by:MikeLong
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.

743 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

12 Experts available now in Live!

Get 1:1 Help Now