Re: Using a Combo Box to Find Records

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
NameOfCombo, and the instruction "Replace NameOfCombo of your combo". I will
[quoted text clipped - 34 lines]
Thanks,
Scott

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200911/1

.



Relevant Pages

  • Re: Conditional Fields
    ... You can cancel the BeforeUpdate event of the control if you wish. ... Thanks for the response, and your suggestion works. ... >> Private Sub Form_BeforeUpdate ...
    (microsoft.public.access.forms)
  • Re: Loop numbering Sequence
    ... >> I have a report that I need to have the numbers 1-7 on. ... >>this function...I would like for it to run a control. ... this suggestion did not run ... >>Private Sub Report_Page ...
    (microsoft.public.access.modulesdaovba)
  • Re: Force subform to always show first record
    ... I tried your suggestion but was still not able to make it ... the focus to each subform, and then set the enter event to ... Private Sub subfrmContactList2Child_Enter ... that refers to the control ...
    (microsoft.public.access.formscoding)
  • Re: Loop numbering Sequence
    ... I am thinking that I will have to use VBA behind my report to drive ... >this function...I would like for it to run a control. ... >I tried one suggestion, but when you skip to the end of the report and go back to page one, the numbering changes. ... >Private Sub Report_Page ...
    (microsoft.public.access.modulesdaovba)
  • Re: Conditional Enabling of Options Group Toggle Button
    ... the question of how you can successfully compile the module? ... BeforeUpdae of Frame1 ... Private Sub Frame1_BeforeUpdate ... there is an AfterUpdate event attached to OffStudyDate ...
    (microsoft.public.access.formscoding)