Combo Box, select Station, opens new form to specified record

F

FreenbGirl

I have an access database that tracks all "stations" I created a main page so
when we have new information to add to an existing station we just select the
station from the combo box drop down list (there are thousands of stations!)
when you select the station you want (ie F12, J31 etc) it opens a new form
(this part i've got done) but the form opens up to record # 2 (F02) which
doesn't match the selection of F12 that I chose from the combo box. How do I
program the code to open the other form and go directly to the station I
chose from the combo box, regardless of what record # it may be??
 
D

Dirk Goldgar

FreenbGirl said:
I have an access database that tracks all "stations" I created a main page
so
when we have new information to add to an existing station we just select
the
station from the combo box drop down list (there are thousands of
stations!)
when you select the station you want (ie F12, J31 etc) it opens a new form
(this part i've got done) but the form opens up to record # 2 (F02) which
doesn't match the selection of F12 that I chose from the combo box. How
do I
program the code to open the other form and go directly to the station I
chose from the combo box, regardless of what record # it may be??


Presumably you have VBA code or a macro running in the combo box's
AfterUpdate or Click event, which opens the form. What you need to do is
provide a "WhereCondition" argument to the OpenForm method or macro action
that specifies the criteria for the form, such that it shows only the
station you want.

Please post the name of the combo box, the name of the field on the form
that contains the station code (e.g., "F12"), and the VBA code or macro
actions that you have for the combo box.
 
F

FreenbGirl

Combo Box = Combo7
Field Name = Station #

DoCmd.OpenForm "Stations 2", acNormal
DoCmd.GoToRecord

Form "Main Page" has combo7 on it. Form "Stations 2" is the form that opens
when you select the station from the list on "Main Page"

"Station #" is a text box that is the Primary Key for the database. Each
station has a different station #. I want "Main Page" to have a drop down
list of all stations in the system, you pick the one u want and the form
"Stations 2" opens up to that station so new information can be input.
(e-mail address removed) if you have more questions.... THANK YOU for ur
help!
 
D

Dirk Goldgar

FreenbGirl said:
Combo Box = Combo7
Field Name = Station #

DoCmd.OpenForm "Stations 2", acNormal
DoCmd.GoToRecord

Form "Main Page" has combo7 on it. Form "Stations 2" is the form that
opens
when you select the station from the list on "Main Page"

"Station #" is a text box that is the Primary Key for the database. Each
station has a different station #. I want "Main Page" to have a drop down
list of all stations in the system, you pick the one u want and the form
"Stations 2" opens up to that station so new information can be input.

Okay, got it. For future reference, it's a good idea to rename controls
from the default names Access generates, such as "Combo7", to meaningful
names like "cboStation". That way, when you refer to them in code or
macros, it's self-documenting. It's also best to avoid having spaces and
funky characters like "#" in your field and control names. For now, though,
I'll assume that the combo is still named "Combo7" and the field is still
named "Station #".

Where you currently have the code to open the form, replace this line:
DoCmd.OpenForm "Stations 2", acNormal

.... with this:

DoCmd.OpenForm "Stations 2", _
WhereCondition:="[Station #]='" & Me!Combo7 & "'"

Note that I have built a criterion that includes single-quotes (') around
the value it gets from Combo7. I'm assuming that no station number will
ever contain the single-quote character. If you think it will, there are
other ways to do this.

Remove this line:
DoCmd.GoToRecord

It will serve no purpose.
 
F

FreenbGirl

You're a genious!! :) This is amazing!! I have so many ideas of things I'd
love to be able to do, but dont know how. If you've ever got some time
email me at (e-mail address removed) and i'll pick your brain!!

THANK YOU THANK YOU THANK YOU!! :)

Dirk Goldgar said:
FreenbGirl said:
Combo Box = Combo7
Field Name = Station #

DoCmd.OpenForm "Stations 2", acNormal
DoCmd.GoToRecord

Form "Main Page" has combo7 on it. Form "Stations 2" is the form that
opens
when you select the station from the list on "Main Page"

"Station #" is a text box that is the Primary Key for the database. Each
station has a different station #. I want "Main Page" to have a drop down
list of all stations in the system, you pick the one u want and the form
"Stations 2" opens up to that station so new information can be input.

Okay, got it. For future reference, it's a good idea to rename controls
from the default names Access generates, such as "Combo7", to meaningful
names like "cboStation". That way, when you refer to them in code or
macros, it's self-documenting. It's also best to avoid having spaces and
funky characters like "#" in your field and control names. For now, though,
I'll assume that the combo is still named "Combo7" and the field is still
named "Station #".

Where you currently have the code to open the form, replace this line:
DoCmd.OpenForm "Stations 2", acNormal

.... with this:

DoCmd.OpenForm "Stations 2", _
WhereCondition:="[Station #]='" & Me!Combo7 & "'"

Note that I have built a criterion that includes single-quotes (') around
the value it gets from Combo7. I'm assuming that no station number will
ever contain the single-quote character. If you think it will, there are
other ways to do this.

Remove this line:
DoCmd.GoToRecord

It will serve no purpose.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

FreenbGirl said:
You're a genious!! :) This is amazing!! I have so many ideas of things
I'd
love to be able to do, but dont know how. If you've ever got some time
email me at [snipped] and i'll pick your brain!!

That would consitute a professional consultation, which I'm not sure you
have in mind. If you do, feel free to contact me to discuss it.

However, these newsgroups are a terrific source of information on how to do
all kinds of things, and Google Groups Advanced Search
(http://groups.google.com/advanced_search) is your friend. On top of that,
may I recommend some good how-to sites:

http://www.mvps.org/access/
The Access Web

http://www.allenbrowne.com/tips.html
Allen Browne's Tips

http://www.granite.ab.ca/accsmstr.htm
Tony Toews' Main Access Page

All of those contain masses of useful information about Access development.

I suggest, by the way, that you not post any un-mangled e-mail address in a
public newsgroup. Spammers regularly troll these groups for e-mail
addresses to be the recipients of their bounty. See what I've done with my
own e-mail address for an example of how to mung an e-mail address so that
people can figure it out but spambots (generally) can't.
THANK YOU THANK YOU THANK YOU!! :)

<lol> I hope you'll accept a single "You're welcome".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top