Is a global variable the fix here?

NYIntensity
Lounger
Posts: 47
Joined: 26 Jan 2010, 01:05

Is a global variable the fix here?

Post by NYIntensity »

When I have a user pick an item from a listbox, I'd like them to be able to double-click on the item and have a form pop up that will show the memo field for the record selected...I've got multiple list boxes that I'd like to be able to apply this to (in any list box that displays records from a particular table, I would like the user to be able to double click and the form with a text box pop up and show the user all the comments). How do I program the text box to look at the item selected in the list box, regardless of the list box that called the form?

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Is a global variable the fix here?

Post by HansV »

You can pass the value of the list box to the popup form in the OpenArgs argument of DoCmd.OpenForm, and inspect the value of the OpenArgs property in the On Open or On Load event of the popup form.

In the code that opens the popup form:

DoCmd.OpenForm FormName:="frmPopup", WindowMode:=acDialog, OpenArgs:=Me.lstList

In the On Open or On Load event of the popup form:

If Not IsNull(Me.OpenArgs) Then
...
End If

See OpenForm method and OpenArgs property.
Best wishes,
Hans

NYIntensity
Lounger
Posts: 47
Joined: 26 Jan 2010, 01:05

Re: Is a global variable the fix here?

Post by NYIntensity »

Awesome...thanks!

NYIntensity
Lounger
Posts: 47
Joined: 26 Jan 2010, 01:05

Re: Is a global variable the fix here?

Post by NYIntensity »

This works perfect, for one form... when I try to apply it to any other listbox controls, I double-click and get the error "An expression you entered is the wrong data type for one of the arguments". When checking what the openargs argument is, it reads 'Null'. Screenshot attached :)
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Is a global variable the fix here?

Post by HansV »

Null shouldn´t be a problem here, but try

..., OpenArgs:=CStr(Me.lstOne)
Best wishes,
Hans

NYIntensity
Lounger
Posts: 47
Joined: 26 Jan 2010, 01:05

Re: Is a global variable the fix here?

Post by NYIntensity »

Hm... well, I put a text box on the form to =lstone, as I select an item, the text box remains blank... does that mean the listbox is corrrupted?

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Is a global variable the fix here?

Post by HansV »

Is that on the first form or on the comments form?
Best wishes,
Hans

NYIntensity
Lounger
Posts: 47
Joined: 26 Jan 2010, 01:05

Re: Is a global variable the fix here?

Post by NYIntensity »

The first form.

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Is a global variable the fix here?

Post by HansV »

In that case, the text box should display the value of the list box (which is not necessarily the displayed value - that depends on the column settings).
Best wishes,
Hans

NYIntensity
Lounger
Posts: 47
Joined: 26 Jan 2010, 01:05

Re: Is a global variable the fix here?

Post by NYIntensity »

Right...I know that, but it's not working - any ideas other than form corruption?

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Is a global variable the fix here?

Post by HansV »

I'm afraid not, I'd have to see (a stripped down and zipped) copy of the database.
Best wishes,
Hans

NYIntensity
Lounger
Posts: 47
Joined: 26 Jan 2010, 01:05

Re: Is a global variable the fix here?

Post by NYIntensity »

Attached :)

Side note - what are the upload restrictions here in the new lounge? I know they (used to be) 100kb.
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Is a global variable the fix here?

Post by HansV »

Try

=[lstOne].[Column](0)

if you want to see the value (hidden) first column of the list box (the ID), or

=[lstOne].[Column](1)

if you want to see the value of the first displayed column (the Update_Name).

BTW, the maximum size for an attachment here is 256 KB.
Best wishes,
Hans

NYIntensity
Lounger
Posts: 47
Joined: 26 Jan 2010, 01:05

Re: Is a global variable the fix here?

Post by NYIntensity »

Using .column worked...I thought I'd tried it already, perhaps my it was all in the execution though. Thanks :)