Checkbox with combo

A

Anne

I have a combo box to select a job. The JobID is an autonumber, the actual
jobnumber is JobNo field. The contractor bids on new job and it is added to
the jobs Table without the job number, and the bidjobs are listed at the
bottom of the combobox.

I would like to be able to have a checkbox on the form, which when checked
shows in the combo box only the jobs without jobNo meaning the bidjobs and
if unchecked only the jobs with JobNo.

Is that possible?
Anne
 
G

Graham Mandeno

Hi Anne

You can change the RowSource of your combo box at runtime.

Let's say your RowSource showing all jobs is a query "qrycboJobList", and
one of the fields in the query is JobNo. Also, say your combo box's name is
"cboJobList", and youor checkbox is called "chkBidJobsOnly"

You can set the RowSource of cboJobList initially to be qrycboJobList. Then
write the following AfterUpdate event procedure for the checkbox:

Private Sub chkBidJobsOnly_AfterUpdate()
With cboJobList
If chkBidJobsOnly <> 0 then
.RowSource = "Select * from qrycboJobList where JobNo is Null"
Else
.RowSource = "qrycboJobList"
End If
End With
End Sub
 
A

Anne

Thanks for your help, it workes sometimes, but it keeps coming back with a
rowsource error. I left the checkbox with the name you gave it. My combo is
based on cboJobContractor. The combobox is JobSelect, the bound field is
JobId, visible is field1, which is jobno, and field2 which is JobName.

Private Sub chkBidJobsOnly_AfterUpdate()
With cboJobList
If chkBidJobsOnly <> 0 Then
.RowSource = "Select * from cbojobContractor where JobNo is Null"
Else
.RowSource = "cboJobContractor"
End If
End With

End Sub

Where did I go wrong?
Anne

Graham Mandeno said:
Hi Anne

You can change the RowSource of your combo box at runtime.

Let's say your RowSource showing all jobs is a query "qrycboJobList", and
one of the fields in the query is JobNo. Also, say your combo box's name is
"cboJobList", and youor checkbox is called "chkBidJobsOnly"

You can set the RowSource of cboJobList initially to be qrycboJobList. Then
write the following AfterUpdate event procedure for the checkbox:

Private Sub chkBidJobsOnly_AfterUpdate()
With cboJobList
If chkBidJobsOnly <> 0 then
.RowSource = "Select * from qrycboJobList where JobNo is Null"
Else
.RowSource = "qrycboJobList"
End If
End With
End Sub

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Anne said:
I have a combo box to select a job. The JobID is an autonumber, the actual
jobnumber is JobNo field. The contractor bids on new job and it is added to
the jobs Table without the job number, and the bidjobs are listed at the
bottom of the combobox.

I would like to be able to have a checkbox on the form, which when checked
shows in the combo box only the jobs without jobNo meaning the bidjobs and
if unchecked only the jobs with JobNo.

Is that possible?
Anne
 
G

Graham Mandeno

Well, I can't see anything wrong with your code. cboJobContractor is the
name of the unfiltered rowsource query, right?

Is JobNo in the bound column of the combobox? If so, then you might have
trouble with a rowsource where the bound column is null.

What do you mean by "it works sometimes"? Does it work when the checkbox is
checked, or when it is not? Or maybe a bit of both? Does the contents of
the list change when the checkbox is clicked? And what eactly is the
"rowsource error" that you are getting?

--
Graham

Graham Mandeno [Access MVP]
Auckland, New Zealand

Anne said:
Thanks for your help, it workes sometimes, but it keeps coming back with a
rowsource error. I left the checkbox with the name you gave it. My combo is
based on cboJobContractor. The combobox is JobSelect, the bound field is
JobId, visible is field1, which is jobno, and field2 which is JobName.

Private Sub chkBidJobsOnly_AfterUpdate()
With cboJobList
If chkBidJobsOnly <> 0 Then
.RowSource = "Select * from cbojobContractor where JobNo is Null"
Else
.RowSource = "cboJobContractor"
End If
End With

End Sub

Where did I go wrong?
Anne

Graham Mandeno said:
Hi Anne

You can change the RowSource of your combo box at runtime.

Let's say your RowSource showing all jobs is a query "qrycboJobList", and
one of the fields in the query is JobNo. Also, say your combo box's
name
is
"cboJobList", and youor checkbox is called "chkBidJobsOnly"

You can set the RowSource of cboJobList initially to be qrycboJobList. Then
write the following AfterUpdate event procedure for the checkbox:

Private Sub chkBidJobsOnly_AfterUpdate()
With cboJobList
If chkBidJobsOnly <> 0 then
.RowSource = "Select * from qrycboJobList where JobNo is Null"
Else
.RowSource = "qrycboJobList"
End If
End With
End Sub

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Anne said:
I have a combo box to select a job. The JobID is an autonumber, the actual
jobnumber is JobNo field. The contractor bids on new job and it is
added
to
the jobs Table without the job number, and the bidjobs are listed at the
bottom of the combobox.

I would like to be able to have a checkbox on the form, which when checked
shows in the combo box only the jobs without jobNo meaning the bidjobs and
if unchecked only the jobs with JobNo.

Is that possible?
Anne
 
A

Anne

With your help, I figured this one out too. You had it right, I forgot to
change the name of my combobox from cboJobList to the actual name which is
JobSelect.
Thank you,
Annelie


Graham Mandeno said:
Well, I can't see anything wrong with your code. cboJobContractor is the
name of the unfiltered rowsource query, right?

Is JobNo in the bound column of the combobox? If so, then you might have
trouble with a rowsource where the bound column is null.

What do you mean by "it works sometimes"? Does it work when the checkbox is
checked, or when it is not? Or maybe a bit of both? Does the contents of
the list change when the checkbox is clicked? And what eactly is the
"rowsource error" that you are getting?

--
Graham

Graham Mandeno [Access MVP]
Auckland, New Zealand

Anne said:
Thanks for your help, it workes sometimes, but it keeps coming back with a
rowsource error. I left the checkbox with the name you gave it. My combo is
based on cboJobContractor. The combobox is JobSelect, the bound field is
JobId, visible is field1, which is jobno, and field2 which is JobName.

Private Sub chkBidJobsOnly_AfterUpdate()
With cboJobList
If chkBidJobsOnly <> 0 Then
.RowSource = "Select * from cbojobContractor where JobNo is Null"
Else
.RowSource = "cboJobContractor"
End If
End With

End Sub

Where did I go wrong?
Anne

Graham Mandeno said:
Hi Anne

You can change the RowSource of your combo box at runtime.

Let's say your RowSource showing all jobs is a query "qrycboJobList", and
one of the fields in the query is JobNo. Also, say your combo box's
name
is
"cboJobList", and youor checkbox is called "chkBidJobsOnly"

You can set the RowSource of cboJobList initially to be qrycboJobList. Then
write the following AfterUpdate event procedure for the checkbox:

Private Sub chkBidJobsOnly_AfterUpdate()
With cboJobList
If chkBidJobsOnly <> 0 then
.RowSource = "Select * from qrycboJobList where JobNo is Null"
Else
.RowSource = "qrycboJobList"
End If
End With
End Sub

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

I have a combo box to select a job. The JobID is an autonumber, the actual
jobnumber is JobNo field. The contractor bids on new job and it is added
to
the jobs Table without the job number, and the bidjobs are listed at the
bottom of the combobox.

I would like to be able to have a checkbox on the form, which when checked
shows in the combo box only the jobs without jobNo meaning the
bidjobs
and
if unchecked only the jobs with JobNo.

Is that possible?
Anne
 

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