Filter records from combo box query

J

Julia

Hi,

I would like to add a function to a database so that:
* users click on a command button on one form
* a pop up window with a combo box appears to allow people to select a
project owner name.
*a second form opens with only the projects from that project owner.

But as a newbie I am finding it rather difficult.

Can you help me?

Thanks,
Julia
 
J

Jeanette Cunningham

Hi Julia,
the post doesn't say how much coding you have done with Access, so I am
guessing about how much code and explanations to put in here.
--for the click event of the cmd button put code something like this:
DoCmd.OpenForm "frmOwner", , , , , acDialog

--this will open the form that has the combo for project owner and the main
form will wait until a user closes frmOwner.
--instead of closing frmOwner you can just hide it so that you can get the
user's choice from the combo
--put a save button of frmOwner
--code its click event me.visible = false
--now frmOwner will be open but invisible
--to get the user's choice put code something like this
-- with forms!frmOwner
if len(.cboProjectOwner) >0 then
strLinkCriteria = "[OwnerID] = " & .cboProjectOwner & ""
else
end if
end with

so we have something like below:

Private cmdGetProjectOwner_Click()
Dim strLinkCriteria as string

DoCmd.OpenForm "frmOwner", , , , , acDialog
with forms!frmOwner
if len(.cboProjectOwner) >0 then
strLinkCriteria = "[OwnerID] = " & .cboProjectOwner & ""
else
end if
end with
docmd.close acform, "frmOwner"
docmd.openform "frmProject", , , strLinkCriteria
docmd.close acform, Me.name

End sub

** if OwnerID as a text field then use
strLinkCriteria = "[OwnerID] = """ & cboProjectOwner & """"

frmOwner is the name of the form with the combo
frmProject is the form that opens with the projects from that project owner
OwnerID is the bound column of the combo

Jeanette Cunningham
 
J

Julia

Thanks Jeanette, I don't have much experience coding with Access, so I will
need some time to work out your answer and see if it does what I would like.
I will let you know how it goes.

Jeanette Cunningham said:
Hi Julia,
the post doesn't say how much coding you have done with Access, so I am
guessing about how much code and explanations to put in here.
--for the click event of the cmd button put code something like this:
DoCmd.OpenForm "frmOwner", , , , , acDialog

--this will open the form that has the combo for project owner and the main
form will wait until a user closes frmOwner.
--instead of closing frmOwner you can just hide it so that you can get the
user's choice from the combo
--put a save button of frmOwner
--code its click event me.visible = false
--now frmOwner will be open but invisible
--to get the user's choice put code something like this
-- with forms!frmOwner
if len(.cboProjectOwner) >0 then
strLinkCriteria = "[OwnerID] = " & .cboProjectOwner & ""
else
end if
end with

so we have something like below:

Private cmdGetProjectOwner_Click()
Dim strLinkCriteria as string

DoCmd.OpenForm "frmOwner", , , , , acDialog
with forms!frmOwner
if len(.cboProjectOwner) >0 then
strLinkCriteria = "[OwnerID] = " & .cboProjectOwner & ""
else
end if
end with
docmd.close acform, "frmOwner"
docmd.openform "frmProject", , , strLinkCriteria
docmd.close acform, Me.name

End sub

** if OwnerID as a text field then use
strLinkCriteria = "[OwnerID] = """ & cboProjectOwner & """"

frmOwner is the name of the form with the combo
frmProject is the form that opens with the projects from that project owner
OwnerID is the bound column of the combo

Jeanette Cunningham


Julia said:
Hi,

I would like to add a function to a database so that:
* users click on a command button on one form
* a pop up window with a combo box appears to allow people to select a
project owner name.
*a second form opens with only the projects from that project owner.

But as a newbie I am finding it rather difficult.

Can you help me?

Thanks,
Julia
 
J

Julia

Hi Jeanette,

I hope I don't depress you but I couldn't get your suggestion to work. I did
find a way to work around the problem by creating a form with only a combo
box that referred to the project owner's name. The I used the (oh no!) wizard
to make a button to open the other form and only show the records from that
project owner. It seems to work!

Julia

Julia said:
Thanks Jeanette, I don't have much experience coding with Access, so I will
need some time to work out your answer and see if it does what I would like.
I will let you know how it goes.

Jeanette Cunningham said:
Hi Julia,
the post doesn't say how much coding you have done with Access, so I am
guessing about how much code and explanations to put in here.
--for the click event of the cmd button put code something like this:
DoCmd.OpenForm "frmOwner", , , , , acDialog

--this will open the form that has the combo for project owner and the main
form will wait until a user closes frmOwner.
--instead of closing frmOwner you can just hide it so that you can get the
user's choice from the combo
--put a save button of frmOwner
--code its click event me.visible = false
--now frmOwner will be open but invisible
--to get the user's choice put code something like this
-- with forms!frmOwner
if len(.cboProjectOwner) >0 then
strLinkCriteria = "[OwnerID] = " & .cboProjectOwner & ""
else
end if
end with

so we have something like below:

Private cmdGetProjectOwner_Click()
Dim strLinkCriteria as string

DoCmd.OpenForm "frmOwner", , , , , acDialog
with forms!frmOwner
if len(.cboProjectOwner) >0 then
strLinkCriteria = "[OwnerID] = " & .cboProjectOwner & ""
else
end if
end with
docmd.close acform, "frmOwner"
docmd.openform "frmProject", , , strLinkCriteria
docmd.close acform, Me.name

End sub

** if OwnerID as a text field then use
strLinkCriteria = "[OwnerID] = """ & cboProjectOwner & """"

frmOwner is the name of the form with the combo
frmProject is the form that opens with the projects from that project owner
OwnerID is the bound column of the combo

Jeanette Cunningham


Julia said:
Hi,

I would like to add a function to a database so that:
* users click on a command button on one form
* a pop up window with a combo box appears to allow people to select a
project owner name.
*a second form opens with only the projects from that project owner.

But as a newbie I am finding it rather difficult.

Can you help me?

Thanks,
Julia
 

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