Results 1 to 5 of 5
  1. #1
    rogdawg is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    5

    How to put code in form event.

    I have created a simple form in my Access database. The form has a combo box on it (cboMyCombo). I "drew" the combo box on the form using the toolbox from the Design tab of the ribbon while in "Form" view. I have insured that the combo box is named correctly.

    In the form's Load event, I am trying to use that combo box in code, like this:
    Private Sub Form_Load()
    SomeFunctionThatExpectsComboBox cboMyCombo, true
    End Sub

    When this code runs, I get:
    Run-time error '91':
    Object variable or With block variable not set

    When I am creating the code, and I type "Me." the intellisense lists the cboMyCombo box control that I created so, it appears everything is ok.

    Can someone help me figure out why the control appears on the form, and why it is reflected in intellisense but, it is NULL when the code runs?

    Thanks for any help you can provide.

  2. #2
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Hi,

    presuming that the content of the combobox and "True" are 2 input parameters of the function SomeFunctionThatExpectsComboBox and that the function returns a string, you can try:

    Private Sub Form_Load()
    dim strReturnValue as string
    strReturnValue = SomeFunctionThatExpectsComboBox(me.cboMyCombo, True)
    End Sub


    If SomeFunctionThatExpectsComboBox is a sub, not a function, you can try:

    Private Sub Form_Load()
    call SomeFunctionThatExpectsComboBox(me.cboMyCombo, True)
    End Sub

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    How about posting the SomeFunctionThatExpectsComboBox function so we can see it?

  4. #4
    rogdawg is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    5

    Thank you for your responses

    I figured out the problem. The function I was trying to call, while passing the combo box as an argument, was defined in separate class. I was not instantiating the class before calling the function, and that was the source of the error.

    The thing that confused me was that, when in break mode, if I held the cursor over the combo box argument, the tool-tip that appeared stated that the combo box was NULL so, I thought that was the cause of the problem.

    So, I did some testing by looping through the combo box's item data within the Form_Load event. After I confirmed that the combo box was fine, I then realized my bone-headed mistake.

    Thank you for your help. We can chalk this one up to User Brain Glitch.

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Excellent! It is always better if the OP solves their own issue and posts the solution. More learning takes place. Thank you for posting back.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Form level mouseup event not firing
    By Philhoop in forum Forms
    Replies: 3
    Last Post: 07-22-2010, 09:41 AM
  2. Before query event when opening form
    By tuna in forum Forms
    Replies: 7
    Last Post: 05-31-2010, 10:35 AM
  3. Replies: 0
    Last Post: 03-11-2010, 02:11 AM
  4. Form does not update after event
    By pedro in forum Forms
    Replies: 10
    Last Post: 12-23-2009, 07:54 AM
  5. Form Event Question
    By protean_being in forum Forms
    Replies: 3
    Last Post: 05-06-2008, 10:43 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums