Combo box problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I converted an Access 97 database into Access 2000. The way a particular combo box in a form worked was when you selected a person in the combo box it would display their name in a text box on the form. Instead what happens is no matter who you select in the combo box the text box only displays the name of the first person you selected. How can I fix this?
 
Anna

Combo boxes are based on a RowSource. What is the SQL statement that this
combobox is using.

More info, please...

Jeff Boyce
<Access MVP>
 
Anna

One possibility is that the control is unbound -- what is the Control
Source?
 
Anna

I don't know "who to blame", but it sounds like if you re-bind that control
to the correct underlying field, you'll be back where you want to be.

Jeff Boyce
<Access MVP>
 
Anna

What do you mean (what is your definition of) when you say "re-bind the
control" -- we may not mean the same thing with that phrase.

Jeff Boyce
<Access MVP>
 
It didn't have a control source so I specified the control source which is the employee name from the employee table. But it still does not work properly. No matter who you select in the combo box the text box only displays the name of the first person you selected.

The Control Source should - MUST! - be blank. What's happening is that
you are overwriting the name in the first record with whichever record
you select.
 
John

When I had the control source blank it still was overwriting the record. You described the problem exactly, it is overwriting the name in the first record with the record selected. How do I fix this database from doing that
 
John,

When I had the control source blank it still was overwriting the record. You described the problem exactly, it is overwriting the name in the first record with the record selected. How do I fix this database from doing that?

Please post your code. A blank Control Source - an unbound combo box -
cannot overwrite anything; there's something else going on!
 
Option Compare Databas
Private Sub Button28_Click(
End Su
Private Sub Detail0_Click(
End Su
Private Sub LastName_BeforeUpdate(Cancel As Integer
End Su
Private Sub NewHrsMissd_BeforeUpdate(Cancel As Integer
End Su
Private Sub NewHrsWkd_BeforeUpdate(Cancel As Integer
End Su
Private Sub PayrollNo_BeforeUpdate(Cancel As Integer
End Su
Private Sub Text12_Click(
End Su
Private Sub Text13_Click(
End Su
Private Sub WorkGroup_BeforeUpdate(Cancel As Integer
End Su
 
Option Compare Database
Private Sub Button28_Click()
End Sub
Private Sub Detail0_Click()
End Sub
Private Sub LastName_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub NewHrsMissd_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub NewHrsWkd_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub PayrollNo_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub Text12_Click()
End Sub
Private Sub Text13_Click()
End Sub
Private Sub WorkGroup_BeforeUpdate(Cancel As Integer)
End Sub

Ummmm... none of these do ANYTHING AT ALL. They should all be deleted,
no point in having an event which is in fact a non-event!

Perhaps I'm misunderstanding this combo box entirely. What do you
want/expect the combo box to do? What are its RowSource,
ControlSource, and Bound Column properties? If you want the combo to
find a record and display it, the combo's AfterUpdate event should
have either some VBA code or a macro to cause that to happen - does
it?
 
The row source is: Select [PayrollNo] From [Employees];
The control source is blank
The bound column is: 1

What it is supposed to do is when you click on the combo box for PayrollNo it should display the person's first name, last name and workgroup in text boxes. But it just keeps overwriting the first record.

Ummmm... No. Combo boxes are not magical; an unbound combo box with no
code will not overwrite anything, nor will it find any record, nor
will it display anything.

You would need to have VBA code in the Combo Box's AfterUpdate event
like (making guesses at the structure of your form and table here):

Private Sub cboPayrollNo_AfterUpdate()
Dim rs As DAO.Recordset
' Open a Recordset based on the Form's Recordsource
Set rs = Me.RecordsetClone
' Find the selected PayrollNo; I assume it's a Text field,
' if it's not leave off the ' characters
rs.FindFirst "[PayrollNo] = '" & Me!cboPayrollNo & "'"
If rs.NoMatch Then
' Warn the user and go to the first record if not found
MsgBox "This employee was not found", vbOKOnly
rs.MoveFirst
End If
Me.Bookmark = rs.Bookmark ' synch the form to the recordset
End Sub
 
I added code in and it still doesn't work.

John Vinson said:
Ummmm... none of these do ANYTHING AT ALL. They should all be deleted,
no point in having an event which is in fact a non-event!

Perhaps I'm misunderstanding this combo box entirely. What do you
want/expect the combo box to do? What are its RowSource,
ControlSource, and Bound Column properties? If you want the combo to
find a record and display it, the combo's AfterUpdate event should
have either some VBA code or a macro to cause that to happen - does
it?
 
I added code in and it still doesn't work.

This sub does nothing. Delete it.
This sub does nothing. Delete it.
This sub does nothing. Delete it.
This sub does nothing. Delete it.
This sub does nothing. Delete it.
This sub does nothing. Delete it.
This sub does nothing. Delete it.
This sub does nothing. Delete it.
This sub does nothing. Delete it.

And please post the code you are actually using, *and also* post the
name of your Form, the Name property of the combo box, and describe
what you want to happen.
 
The form name is EnterOvertimeHours
The combo box property name is PayrollNo

After update it says: EnterOvertimePayrollNoFilter

ummm... where?

One suggested change to the code: take the form reference out of the
text string so that you can find the *value* of the combo box rather
than its *name*.

The code is:
Dim rs As DAO.Recordset
' Open a Recordset based on the Form's Recordsource
Set rs = Me.RecordsetClone
rs.FindFirst "[PayrollNo] = " & Me!cboPayrollNo
If rs.NoMatch Then
' Warn the user and go to the first record if not found
MsgBox "This employee was not found", vbOKOnly
rs.MoveFirst
End If
Me.Bookmark = rs.Bookmark ' synch the form to the recordset
End Sub

If PayrollNo is a Text field rather than a Number, you'll need
quotemarks:

rs.FindFirst "[PayrollNo] = '" & Me!cboPayrollNo & "'"
 
Should the line in the code read rs.FindFirst = & Me!cboPayrollNo

In the event properties it has "EnterOvertimePayrollNoFilter"

John Vinson said:
The form name is EnterOvertimeHours
The combo box property name is PayrollNo

After update it says: EnterOvertimePayrollNoFilter

ummm... where?

One suggested change to the code: take the form reference out of the
text string so that you can find the *value* of the combo box rather
than its *name*.

The code is:
Dim rs As DAO.Recordset
' Open a Recordset based on the Form's Recordsource
Set rs = Me.RecordsetClone
rs.FindFirst "[PayrollNo] = " & Me!cboPayrollNo
If rs.NoMatch Then
' Warn the user and go to the first record if not found
MsgBox "This employee was not found", vbOKOnly
rs.MoveFirst
End If
Me.Bookmark = rs.Bookmark ' synch the form to the recordset
End Sub

If PayrollNo is a Text field rather than a Number, you'll need
quotemarks:

rs.FindFirst "[PayrollNo] = '" & Me!cboPayrollNo & "'"
 
Should the line in the code read rs.FindFirst = & Me!cboPayrollNo

No. It should read what I typed, though I see you have named the
control differently. ASSUMING that the field is named PayrollNo and
the combo box is also named PayrollNo,

rs.FindFirst "[PayrollNo] = " & Me!PayrollNo
In the event properties it has "EnterOvertimePayrollNoFilter"

The Event Property should be

[Event Procedure]

and the name of this sub should be the name of the event - probably

Private Sub cboPayrollNo_AfterUpdate()

if it's the AfterUpdate event (which again *YOU HAVE NOT SAID*; my
telepathy is getting a workout today!)
 
Okay hopefully this will clear things up. In the afterupdate event indicated on the "event" tab of the properties window it says EnterOvertimePayrollNoFilter.

When I add the code that you gave me and select the payroll number from the combo box it doesn't match with the correct name of the employee.

John Vinson said:
Should the line in the code read rs.FindFirst = & Me!cboPayrollNo

No. It should read what I typed, though I see you have named the
control differently. ASSUMING that the field is named PayrollNo and
the combo box is also named PayrollNo,

rs.FindFirst "[PayrollNo] = " & Me!PayrollNo
In the event properties it has "EnterOvertimePayrollNoFilter"

The Event Property should be

[Event Procedure]

and the name of this sub should be the name of the event - probably

Private Sub cboPayrollNo_AfterUpdate()

if it's the AfterUpdate event (which again *YOU HAVE NOT SAID*; my
telepathy is getting a workout today!)
 
Okay hopefully this will clear things up. In the afterupdate event indicated on the "event" tab of the properties window it says EnterOvertimePayrollNoFilter.

This will attempt to execute a Macro named
ENterOvertimePayrollNoFilter. Do you have such a Macro? No? I didn't
think so.

REMOVE EnterOvertimePayrollNoFilter from the event.

Click the ... icon.

Select "Code Builder" from the options you will be presented.

Enter the code I offered, using *your own table and field names* - my
speculations as to what they might have been may be inaccurate.

If you have Lookup fields in your tables, bear in mind that they do
not contain what they appear to contain.
When I add the code that you gave me and select the payroll number from the combo box it doesn't match with the correct name of the employee.

Well, I wish I could help - but again...

I CANNOT SEE YOUR DATABASE

and I'm not telepathic. I'm sorry, Anna, but we're just not
communicating!
 
Back
Top