Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004
    Posts
    133

    Unhappy Unanswered: newbie code reuse

    I have a form A (which have a combobox 'department' inside it) with this simple load event:
    with me.department
    .rowsource= _
    " select departmentid,departmentname from departments " & _
    " where departmentname is not null "
    .limit to listtrue
    end with

    I also have a form B (which have a combobox 'department' inside it) with above simple load event. And I also have a form C (which have a combobox 'department' inside it) with above simple load event.

    My question is how can I do so that I not need write above load event for each form?
    For example in Access module I create sub loadatstartup() with above code
    and then in load event of each form, I simply type loadatstartup only.

    Could anyone give me the detail way of how to do this?
    many thanks

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Create a function in a standard module that contains your code:

    Code:
    Public Function LoadForm(frm As Form)
      with frm.department
         .rowsource= _
         " select departmentid,departmentname from departments " & _
         " where departmentname is not null "
        .limit to listtrue
       end with
    End Function
    Then just call that function each form On Load event:
    Code:
    Private Sub Form_Load()
      LoadForm(Me)
    End Sub
    Inspiration Through Fermentation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •