Using VBA function for Forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alan Brasel

    Using VBA function for Forms

    This is the first time that I have tried to use a function as the
    default value for a form. The function appears to work when I run it in
    VBA, and I have saved it and it shows up in my Module list. However,
    when I make a form, with a text box then in the Default put

    = FunctionName()

    all I get is "#Name?" in the text box.


    Can anyone please help?

    Thanks

    Alan

  • MGFoster

    #2
    Re: Using VBA function for Forms

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    There cannot be a space between the equal sign and the function name.
    The function name must be the name of a function, not the name of a
    module. If it is in a standard module and not in the form's class
    module it must be a Public function NOT a Private function.

    Sometimes the control doesn't pick up the function call until after
    the form has been saved & then re-opened. Try that.

    HTH,

    MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
    Oakland, CA (USA)

    -----BEGIN PGP SIGNATURE-----
    Version: PGP for Personal Privacy 5.0
    Charset: noconv

    iQA/AwUBQCXhBoechKq OuFEgEQI3bwCg2Z SdUPPUhiH7t4YP0 BbHV4cB/14AmgMZ
    ps2WzzFXy1LIHvK YzzDKsAcq
    =vM6p
    -----END PGP SIGNATURE-----


    Alan Brasel wrote:[color=blue]
    > This is the first time that I have tried to use a function as the
    > default value for a form. The function appears to work when I run it in
    > VBA, and I have saved it and it shows up in my Module list. However,
    > when I make a form, with a text box then in the Default put
    >
    > = FunctionName()
    >
    > all I get is "#Name?" in the text box.[/color]

    Comment

    • Bas Cost Budde

      #3
      Re: Using VBA function for Forms

      Alan Brasel wrote:
      [color=blue]
      > This is the first time that I have tried to use a function as the
      > default value for a form. The function appears to work when I run it in
      > VBA, and I have saved it and it shows up in my Module list. However,
      > when I make a form, with a text box then in the Default put
      >
      > = FunctionName()
      >
      > all I get is "#Name?" in the text box.[/color]

      I can duplicate this behavior; it seems to me that you cannot have a
      DefaultValue when the ControlSource is Null.

      Is your textbox bound?

      --
      Bas Cost Budde

      but the domain is nl

      Comment

      • Alan Brasel

        #4
        Re: Using VBA function for Forms

        The text box is UNbound. I found that what I was doing wrong is that I
        named the module the same name as the function - apparently that is not
        allowed. After renaming my module, everything works just fine.

        Thanks for your help.

        Alan

        Bas Cost Budde wrote:
        [color=blue]
        > Alan Brasel wrote:
        >[color=green]
        >> This is the first time that I have tried to use a function as the
        >> default value for a form. The function appears to work when I run it
        >> in VBA, and I have saved it and it shows up in my Module list.
        >> However, when I make a form, with a text box then in the Default put
        >>
        >> = FunctionName()
        >>
        >> all I get is "#Name?" in the text box.[/color]
        >
        >
        > I can duplicate this behavior; it seems to me that you cannot have a
        > DefaultValue when the ControlSource is Null.
        >
        > Is your textbox bound?
        >[/color]

        Comment

        • Alan Brasel

          #5
          Re: Using VBA function for Forms

          I found that what I was doing wrong is that I named the module the same
          name as the function - apparently that is not allowed. After renaming
          my module, everything works just fine.

          Thanks for your help.

          Alan

          MGFoster wrote:
          [color=blue]
          > -----BEGIN PGP SIGNED MESSAGE-----
          > Hash: SHA1
          >
          > There cannot be a space between the equal sign and the function name.
          > The function name must be the name of a function, not the name of a
          > module. If it is in a standard module and not in the form's class
          > module it must be a Public function NOT a Private function.
          >
          > Sometimes the control doesn't pick up the function call until after
          > the form has been saved & then re-opened. Try that.
          >
          > HTH,
          >
          > MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
          > Oakland, CA (USA)
          >
          > -----BEGIN PGP SIGNATURE-----
          > Version: PGP for Personal Privacy 5.0
          > Charset: noconv
          >
          > iQA/AwUBQCXhBoechKq OuFEgEQI3bwCg2Z SdUPPUhiH7t4YP0 BbHV4cB/14AmgMZ
          > ps2WzzFXy1LIHvK YzzDKsAcq
          > =vM6p
          > -----END PGP SIGNATURE-----
          >
          >
          > Alan Brasel wrote:
          >[color=green]
          >> This is the first time that I have tried to use a function as the
          >> default value for a form. The function appears to work when I run it
          >> in VBA, and I have saved it and it shows up in my Module list.
          >> However, when I make a form, with a text box then in the Default put
          >>
          >> = FunctionName()
          >>
          >> all I get is "#Name?" in the text box.[/color]
          >
          >[/color]

          Comment

          • Bas Cost Budde

            #6
            Re: Using VBA function for Forms

            Alan Brasel wrote:
            [color=blue]
            > The text box is UNbound. I found that what I was doing wrong is that I
            > named the module the same name as the function - apparently that is not
            > allowed. After renaming my module, everything works just fine.[/color]

            Indeed. Nor can you name your project the same as a function or a module.
            [color=blue]
            > Thanks for your help.[/color]

            Any time--but how have I helped? ;-)
            --
            Bas Cost Budde

            but the domain is nl

            Comment

            Working...