Full Version: Passing two keys via stLinkCriteria
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
Nyteshade
I have a form with a list box where you can double-click an item and pull up a maintenance form to edit the item selected. Now I've go several of these forms that work, but they all just pass one key field. The sample I have attached uses two key fields from the list box, BUT, the form fails to open with 'form open cancelled' error. My question is, after you take a look at how I've set this up, can two keys fields get passed and if so then what is buggering up my code!?!? Thx for taking a look at it.

stDocName = "frmIssueDetail_editdelete"
key1 = Mid(strIDs, 2, 3)
key2 = Mid(strIDs, 6, 3)
stLinkCriteria = "[issdPrefix]='" & key1 & "'" & " And " & "[issdNumber]='" & key2 & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
GroverParkGeorge
You are concatenating the two keys into a single parameter to pass to the other form.

When your other form opens, you'll have to parse out the two keys again before you can use them to filter the recordset.

Look for the section between the two keys " And " and split the two parts out.

George
Nyteshade
Ooooooooook, lemme research that abit and see what I can come up with...
Nyteshade
I know you're pullin' for me Grover, but sorry, I don't see what yer talkin'bout there boss. I tried replacing the "And" with a ";" and I gen a syntax error. When I use a 'space' then I gen a 'missing operator' error. My assumption is that all I need to do is drop [issdPrefix] and [issdNumber] into something like a 'link buffer" where the variables get recognized by the called form and it says 'oh, there are the valid variables that hold values that I can use'. I went back and looked at the forms that I use with only one passed variable and they work without having to do anything special. So clue me the fix or a better clue. Thx!
niesz
A couple of things that I can see are incorrect...

This line:
stLinkCriteria = "[issdPrefix]='" & key1 & "'" & " And " & "[issdNumber]='" & key2 & "'"

..needs to be..
stLinkCriteria = "[issdNumber]=" & key1 & " And " & "[issdPrefix]='" & key2 & "'"

You were passing the wrong key in the wrong place. Also IssdNumber is an AutoNumber, which means it is stored as a Long, so you do not wrap the criteria with quotes.

SIDE POINT:
This:
Dim strIDs, key1, key2, stDocName, stLinkCriteria As String

..does not do what you expect. It only declares stLinkCriteria as a string. All of the others are Variants. Use:

Dim strIDs As String
Dim key1 As String
Dim key2 As String
Dim stDocName As String
Dim stLinkCriteria As String

I think George was thinking you were passing OpenArgs not Link Criteria. confused.gif
niesz
Also, the code you were using to retrieve the values from the listbox is code for a Simple or Extended type listbox. When MultiSelect is set to None you can access the values much easier.

All the code in the entire procedure can be replaced with a single line:

CODE
    DoCmd.OpenForm "frmIssueDetail_editdelete", , , "[issdNumber]=" & Me.lstIssueDetail & " And " & _

        "[issdPrefix]='" & Me.lstIssueDetail.Column(1) & "'"


Technically you don't even need the brackets around the fieldnames.
Nyteshade
Thanks niesz, I discovered that I had my key1 and key2 switched late yesterday but even though I switched them did not solve my problem. I also discoverd that I 'thought' I needed a 'compound' key to access my Issue Detail table (as though it were a junction table) but since the key to it is autonumber then I don't really need the 'prefix' to get the record I need (I get hung up on normalizing keys sometimes, but now I've got options!). That said, your code looks exactly what should be done and thank you very much for the explanations on the Dim declarations. Also, thanks for the 'DoCmd.OpenForm line, I had no idea you could do that! I'll be trying it out shortly. I'll let you know how it goes....
Nyteshade
Holy moly! I implemented your code and it worked the first time! Thanks again, I've been sweating over that issue for daze!
niesz
NP.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.