Renaming ComboBox Disables It

G

Guest

In Access 2003 I used the Combo Box Wizard to place a combo box on a form and
selected: Find a record on my form based on the value I selected in my combo
box. The wizard named the combo box combo8. The combo box worked until I
changed its name to cboFind. When I changed the name back to combo8, it
started working again. I was sure I renamed combo boxes in previous versions
of Access with no adverse effects. Are there other objects I should avoid
renaming?
 
K

Kai Apel \(Berlin\)

look at the code behind the action after update (pressing Alt + F11 you can
look at the Code). When you´re renaming the Combobox you also have to change
the name of the Sub! The Sub wouldn´t renamend by renaming only the
combobox!!!
Change your Name of your Sub to the new name of your Combobox and that´s
it!!
I guess, the Sub called Private Sub combo8.....!

Hope that helps

Greeting from Berlin Kai Apel
 
R

Roger Carlson

Actually, this has always been the case. The combo box wizard writes code
that is specific to the name of the combo. Once you rename it, the code
doesn't run. But don't dispair. You CAN fix it!

If your code looks like this:
Private Sub Combo3_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[MyID] = " & Me![Combo3]
Me.Bookmark = rs.Bookmark
End Sub

Change it to:
Private Sub cboFind_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[MyID] = " & Me![cboFind]
Me.Bookmark = rs.Bookmark
End Sub

Notice I changed both the subroutine name and the reference to the control
in the FindFirst.

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
G

George Nicholson

You can rename the combo box. You just need to make sure that you *also*
change the name in any code that refers to that combo box because it won't
be changed automatically. (This is why it stopped working: the code is still
using the "old" name, so it never runs.)

In your case, since you are finding a record based on the combo selection,
the wizard created code for the combo's AfterUpdate event. Since that combo
name no longer exists, you need to make some edits in the VB editor:
Private Sub Combo8_AfterUpdate()
should be changed to
Private Sub cboFind_AfterUpdate()

You would also need to change any references to Combo8 within the
AfterUpdate.
 

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

Similar Threads


Top