Results 1 to 4 of 4

Thread: VB question

  1. #1
    Join Date
    Mar 2004
    Posts
    13

    Question Unanswered: VB question

    I have a this function:

    Function StartWeek() As String
    StartWeek = [Forms]![frmStaffing Profile]![cboStartWeek]
    End Function

    If I would like to use the same function from another form, would it be possible to use a function somehow like this??

    Function StartWeek() As String
    StartWeek = [Forms]![ functionGetCurrentForm() ]![cboStartWeek]
    End Function

    //pete

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    You could pass the current form as a variable if you'd like. Something like:

    Function StartWeek(frm As form) As String
    StartWeek = frm![cboStartWeek]
    End Function

    Usage:

    s = StartWeek(me)

  3. #3
    Join Date
    Feb 2004
    Posts
    142
    Be sure to declare the function as public to make the function available to calls outside that form, if it is in the code module of a form then the form must be open to call it. To reference it:

    ReturnValue = Forms!frmFormName.StartWeek()
    KC

  4. #4
    Join Date
    Mar 2004
    Location
    Atlanta, GA
    Posts
    7
    A trick i've learned:

    the form doesn't have to be open to call a public function, IF you fully qualify the reference to the function within its module.

    Ex:

    ReturnValue = Form_frmFormName.StartWeek(frmName)

    it's the "Form_" that tells VBA exactly where to go, regardless of whether or not that form is open.

Posting Permissions

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