Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listbox send selected item to second form 1

Status
Not open for further replies.

p27br

Programmer
Aug 13, 2001
516
GB
Hi

I have a form with a listbox.
The user selects one item then clicks a button which opens a new form which can be one of several depending on the item selected.
the code on the click event should be something like this :
'select case lst.itemselected
'case 1
'open formA
'case 2
'open formB
'case 3
'open formC
what's the syntax I should use for this ?

Second issue : I want to insert the item's bound column value into a field on the new form.
how can I achieve this ?

thanks in advance

paul
 

Paul,

You've more or less got it already. Try the below but expand for all the cases you require.

dim strFormName as string

Select Case me.lstname

case "Variable1"

strFormName = "Name1"

Case "variable2"

strFormName = "Name2"

case else

msgBox "Unknown entry selected!"

end select

---------- The above works out which form to open

---------- This then uses the result to Open the form and assign the list box value to a control on the opened form.


docmd.openform frmname
forms!strFormName!txtcontrol = me.lstname



Hope this helps
 
Yes,

that's what I was missing : the listbox takes the value of the selected item. Thanks !

Now there is still a problem : the syntax of the line

Code:
forms!strFormName!txtcontrol = me.lstname

VBA considers strFormName as the form name, not the value of strFormName which would be frmMyForm
 
Hi again

I figured it out :
Code:
    Forms(strFormName)!lngOutputTypeRef = Me!lstOutputType

thanks for your help !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top