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

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Open Form Based On List Box Selection, Access 2016    
 
   
SheriDi
post Dec 3 2017, 11:04 AM
Post#1



Posts: 115
Joined: 30-January 00
From: SoCal


I want to open a form based on a selection the user makes from a list box. I currently open the form from a subform, but have decided that for my needs a list box would be a little more "elegant", so I'd like to replace the subform with a listbox

So here's the code I am currently using on the subform:

DoCmd.OpenForm "frmScoreCard", acNormal, , "pkGolfRoundID =" & Me.pkGolfRoundID, acFormEdit, acWindowNormal

pkGolfRoundID is in the ListBox, but using the above code, the form won't open. I get the error "Method or data member not found".

What is the proper syntax to refer to the list box on a form.
Go to the top of the page
 
GroverParkGeorge
post Dec 3 2017, 11:22 AM
Post#2


UA Admin
Posts: 31,245
Joined: 20-June 02
From: Newcastle, WA


You need to identify the listbox so that the code "knows" which pkGolfRoundID has been selected in it.

Your current code selects whatever pkGolfRoundID currently has the focus in the form, not the listbox.

Change the reference accordingly.

--------------------
Go to the top of the page
 
SheriDi
post Dec 3 2017, 03:11 PM
Post#3



Posts: 115
Joined: 30-January 00
From: SoCal


That's my problem, I can't figure out how to reference it. I've tried these (among several other things) and can't find the correct syntax:

DoCmd.OpenForm "frmScoreCard", acNormal, , "pkGolfRoundID=" & Me.lstRounds.pkGolfRoundID, acFormEdit, acWindowNormal

DoCmd.OpenForm "frmScoreCard", acNormal, , "pkGolfRoundID=" & Form2!lstRounds.pkGolfRoundID, acFormEdit, acWindowNormal

lstRounds is the name of the Listbox

Go to the top of the page
 
theDBguy
post Dec 3 2017, 03:56 PM
Post#4


Access Wiki and Forums Moderator
Posts: 71,236
Joined: 19-June 07
From: SunnySandyEggo


Hi,

Assuming you are using a button for this code, try using the following and let us know if you get an error with it:

MsgBox Me.ListBoxName

If you don't get an error and got a number (or text) instead, does it match what you're expecting as selected from the Listbox?

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 
SheriDi
post Dec 3 2017, 04:09 PM
Post#5



Posts: 115
Joined: 30-January 00
From: SoCal


Thanks DBGuy, this is the error I get:

Method or Data Member not found.
Go to the top of the page
 
RJD
post Dec 3 2017, 04:32 PM
Post#6


UtterAccess VIP
Posts: 7,850
Joined: 25-October 10
From: Gulf South USA


Hi Sheri: PMFJI, but you might try this ...

DoCmd.OpenForm "frmScoreCard", acNormal, , "pkGolfRoundID=" & Forms!Form2!lstRounds

This assumes that the form name is Form2 (you really should have a better name for this), that lstRounds is the name of the listbox on that form, and that the value in the listbox is numeric. If the value is NOT numeric, but text, then you will have to add some parens to tell Access that the value is text.

This also assumes that there are no other columns in the listbox. If there are multiple columns in the listbox, then you will have to code for the column you want. For example, if there are multiple columns and you want the first column value, you should code something like this ...

Forms!Form2!lstRounds.Column(0)

See if this works better. If we keep failing on this, perhaps you could post the db and someone could take a look. Usually this leads to a quick solution.

HTH
Joe

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
SheriDi
post Dec 3 2017, 04:50 PM
Post#7



Posts: 115
Joined: 30-January 00
From: SoCal


Thanks Joe that did the trick! And yes "Forms2" was just my practice form thumbup.gif
Go to the top of the page
 
RJD
post Dec 3 2017, 08:43 PM
Post#8


UtterAccess VIP
Posts: 7,850
Joined: 25-October 10
From: Gulf South USA


You are very welcome, Sheri, from all of us. Glad that worked. thumbup.gif

Good luck with your project, and let us know if we can be of further assistance.

Regards,
Joe

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    18th December 2017 - 03:45 AM