Re: Using a Combo Box to Find Records
- From: "BruceM via AccessMonster.com" <u54429@uwe>
- Date: Mon, 16 Nov 2009 20:36:02 GMT
I didn't know you understood Jeanette's suggestion based on what you wrote.
You wouldn't be the first person attempting to use a placeholder field or
control name in actual code.
The ItemData code needs to go into the *form's* Load event. A combo box
doesn't have a Load or OnLoad event (at least not in Access 2003 and earlier).
Did that code compile?
When closing a form I like to be specific:
DoCmd.Close acForm, "frmCampaignSummary"
If you are closing the form on which the command button lives you can do:
DoCmd.Close acForm, Me.Name
I can't say exactly what compiling code does, except that it will identify
syntax errors, references to non-existent fields and controls (perhaps due to
spelling errors), functions with the wrong number of arguments (for instance,
Left("Test text") would generate a compile error because you need to specify
the number of characters), functions it doesn't recognize (again, spelling
errors perhaps). A database with uncompiled code could harbor an error. In
some cases this would be code that runs only when certain conditions are met,
so it could be a while before the error happens. I believe compiling
improves performance, but most of the time probably not enough to make much
of a difference.
As an aside, Option Explict is a good thing to have at the top. It means you
have to declare all variables. If you do not, Access tends to assume
anything it doesn't recognize is a variant, which can lead to very
frustrating troubleshooting just because you typed something incorrectly.
The difference between lngID and IngID may not be readily apparent by eye
(one uses a lower case "l" and the other an upper case "I", in case you are
viewing this with sans serif font).
Scott_Brasted wrote:
Bruce,
Without getting frustrated or upset, I know what Jeanette wanted me to do
with the code. I changed the cbo to the name I have in my form when I got her
answer. The code she suggested is not doing anything and I am tryng to figure
out why. I have it in the on_load event and I have an empty cbo when I open
the form. As I mentioned, the data is correct and I can choose an entry to
click on and that will be correct also. Everything seems fine except for the
empty cbo.
Here is the entire code for that form:
Option Compare Database
Option Explicit
Private Sub CboMoveTo_AfterUpdate()
Dim rs As DAO.Recordset
If Not IsNull(Me.cboMoveTo) Then
'Save before move.
If Me.Dirty Then
Me.Dirty = False
End If
'Search in the clone set.
Set rs = Me.RecordsetClone
rs.FindFirst "[SetupID] = " & Me.cboMoveTo
If rs.NoMatch Then
MsgBox "Not found: filtered?"
Else
'Display the found record in the form.
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
End If
End Sub
Private Sub cmdCloseCampaignPledgeSummaryForm_Click()
On Error GoTo Err_cmdCloseCampaignPledgeSummaryForm_Click
DoCmd.Close
Exit_cmdCloseCampaignPledgeSummaryForm_C:
Exit Sub
Err_cmdCloseCampaignPledgeSummaryForm_Click:
MsgBox Err.Description
Resume Exit_cmdCloseCampaignPledgeSummaryForm_C
End Sub
Private Sub cboMoveTo_OnLoad()
Me.[cboMoveTo] = Me.[cboMoveTo].ItemData(0)
End Sub
By the way,I just did as you suggested and commented out the code for the
label the switchboard wtill works fine and the code compiled in a few seconds.
Can you explain what happens when I compile the code? Does the db work
differently or better?
Thanks,
Scott
Jeanette did not know the name of your combo box, so she used a generic name[quoted text clipped - 34 lines]
NameOfCombo, and the instruction "Replace NameOfCombo of your combo". I will
Thanks,
Scott
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200911/1
.
- Follow-Ups:
- Re: Using a Combo Box to Find Records
- From: Scott_Brasted via AccessMonster.com
- Re: Using a Combo Box to Find Records
- References:
- Using a Combo Box to Find Records
- From: Scott_Brasted
- Re: Using a Combo Box to Find Records
- From: Jeanette Cunningham
- Re: Using a Combo Box to Find Records
- From: Jeanette Cunningham
- Re: Using a Combo Box to Find Records
- From: Scott_Brasted via AccessMonster.com
- Re: Using a Combo Box to Find Records
- From: BruceM via AccessMonster.com
- Re: Using a Combo Box to Find Records
- From: Scott_Brasted via AccessMonster.com
- Re: Using a Combo Box to Find Records
- From: BruceM via AccessMonster.com
- Re: Using a Combo Box to Find Records
- From: Scott_Brasted via AccessMonster.com
- Using a Combo Box to Find Records
- Prev by Date: Re: How to set the Calendar control's background as transaparent?
- Next by Date: Re: Using a Combo Box to Find Records
- Previous by thread: Re: Using a Combo Box to Find Records
- Next by thread: Re: Using a Combo Box to Find Records
- Index(es):
Relevant Pages
|