Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    Feb 2002
    Posts
    537
    Thanks
    0
    Thanked 0 Times in 0 Posts

    reuse of function (Access 2000)

    I want to use a function that is valid for different forms, where each forms contains one and the same
    control.This control is called by me afid and exists in all forms.I want to use a function that could be valid for all forms
    that contain this control.The function is dependant on a opption box in the main form where i choose the number of the office.

    The function i gave cited below gives the error "Object required".
    Can i receive an advice what is wrong wth my function and secondly how cani rationalize it?

    In the brackets below i have tried to asign the control called afid,existing in all forms

    Public Function FncAfid(afid)
    Forms!FCustomers!kindid.DefaultValue = 1
    Select Case Forms![FOrderInformation]![office]
    Case 1
    afid.DefaultValue = 1
    Case 2
    afid.DefaultValue = 2
    Case 3
    afid.DefaultValue = 3
    Case 4
    afid.DefaultValue = 4
    Case 5
    afid.DefaultValue = 5
    Case 6
    afid.DefaultValue = 6
    Case 7
    afid.DefaultValue = 7
    Case 8
    afid.DefaultValue = 8
    Case 9
    afid.DefaultValue = 9
    Case 10
    afid.DefaultValue = 10
    etc
    ets
    End Select
    End Function

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: reuse of function (Access 2000)

    I would write the function as follows:

    Public Function FncAfid(ctl As Control)
    Forms!FCustomers!kindid.DefaultValue = 1
    ctl.DefaultValue = Forms![FOrderInformation]![office]
    End Function

    To call it, use FncAfid([Afid]).

  3. #3
    4 Star Lounger
    Join Date
    Feb 2002
    Posts
    537
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: reuse of function (Access 2000)

    May i have some further help?I am sorry i receive again the message object required. I think i did not explain myself clear.
    The default values in my forms depend on the option choice in the main form FOrderinformation.
    if i have an option choice 1 in the main form,e.g.
    Forms![FOrderInformation]![office] = 1
    then the control afid, which is in another form, must have default number 1:
    Forms!FCustomers!afid .DefaultValue = 1

    The following code also gives me the error :Object required"


    Public Function FncAfid(frm As Form) 'i call the function with Fncafid(Me.Name)
    Select Case Forms![FOrderInformation]![office]
    Case 1 ' i.e. i have selected option 1 in the main form
    frm![afid].DefaultValue = 1
    Case 2
    frm![afid].DefaultValue = 2
    Case 3
    frm![afid].DefaultValue = 3
    Case 4
    frm![afid].DefaultValue = 4
    Case 5
    frm![afid].DefaultValue = 5
    Case 6
    frm![afid].DefaultValue = 6
    Case 7
    frm![afid].DefaultValue = 7
    Case 8
    frm![afid].DefaultValue = 8
    Case 9
    frm![afid].DefaultValue = 9
    End Select
    End Function

    Thank you in advance


    Best regards

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: reuse of function (Access 2000)

    The argument to your function is of type Form, but you pass it a string: Me.Name, so you have a type conflict. You should pass the form itself when you call the function:

    FncAfid(Me)

Posting Permissions

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