UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Passing two keys via stLinkCriteria    
 
   
Nyteshade
post Sep 13 2006, 03:09 PM
Post #1

UtterAccess Ruler
Posts: 1,289
From: Ohio, USA



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
Attached File(s)
Attached File  linkcriteria.zip ( 20.02K ) Number of downloads: 5
 
Go to the top of the page
 
+
GroverParkGeorge
post Sep 13 2006, 03:16 PM
Post #2

UA Admin
Posts: 19,227
From: Newcastle, WA



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
Go to the top of the page
 
+
Nyteshade
post Sep 13 2006, 03:29 PM
Post #3

UtterAccess Ruler
Posts: 1,289
From: Ohio, USA



Ooooooooook, lemme research that abit and see what I can come up with...
Go to the top of the page
 
+
Nyteshade
post Sep 13 2006, 03:45 PM
Post #4

UtterAccess Ruler
Posts: 1,289
From: Ohio, USA



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!
Go to the top of the page
 
+
niesz
post Sep 13 2006, 07:38 PM
Post #5

Utter A-fishin'-ado
Posts: 17,723
From: Cincinnati, Ohio, USA . . . ><((((°>



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. (IMG:http://www.utteraccess.com/forum/style_emoticons/default/confused.gif)
Go to the top of the page
 
+
niesz
post Sep 13 2006, 07:46 PM
Post #6

Utter A-fishin'-ado
Posts: 17,723
From: Cincinnati, Ohio, USA . . . ><((((°>



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.
Go to the top of the page
 
+
Nyteshade
post Sep 14 2006, 07:16 AM
Post #7

UtterAccess Ruler
Posts: 1,289
From: Ohio, USA



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....
Go to the top of the page
 
+
Nyteshade
post Sep 14 2006, 07:40 AM
Post #8

UtterAccess Ruler
Posts: 1,289
From: Ohio, USA



Holy moly! I implemented your code and it worked the first time! Thanks again, I've been sweating over that issue for daze!
Go to the top of the page
 
+
niesz
post Sep 14 2006, 07:44 AM
Post #9

Utter A-fishin'-ado
Posts: 17,723
From: Cincinnati, Ohio, USA . . . ><((((°>



NP.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 20th May 2013 - 06:47 AM