Code to set property in form not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert C

    Code to set property in form not working



    I have 2 forms, an unbound which calls a bound form via a command
    button. Both forms have a textbox called TDate. The name of the
    calling form is SelectionFrm. When I set the DefaultValue property of
    the textbox on the called form to:

    =[Forms]![SelectionFrm]![TDate]

    I get exactly what I want in TDate on the called form.

    But if I remove this from the properties and put the following code in
    for the called form's open form event, it doesn't work:

    Me.TDate.Defaul tValue = [Forms]![SelectionFrm]![TDate]

    I put a stop right after this statement. The value of
    Me.TDate.Defaul tValue shows correctly at that point. But on the screen
    it comes up as '12/30/1899'.

    I also tried putting it in the BeforeUpdate event of TDate. That didn't
    work either.

    Any idea why the code doesn't work while the property does? Or is it
    impossible to set default values in code?

    Robert


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Douglas J. Steele

    #2
    Re: Code to set property in form not working

    The Default Value property is text, regardless of what the value is. Try:

    Me.TDate.Defaul tValue = "" & [Forms]![SelectionFrm]![TDate] & ""

    or

    Me.TDate.Defaul tValue = Chr$(34) & [Forms]![SelectionFrm]![TDate] & Chr$(34)


    --
    Doug Steele, Microsoft Access MVP

    (No private e-mails, please)



    "Robert C" <projecttoday@y ahoo.com> wrote in message
    news:40844d9c$0 $201$75868355@n ews.frii.net...[color=blue]
    >
    >
    > I have 2 forms, an unbound which calls a bound form via a command
    > button. Both forms have a textbox called TDate. The name of the
    > calling form is SelectionFrm. When I set the DefaultValue property of
    > the textbox on the called form to:
    >
    > =[Forms]![SelectionFrm]![TDate]
    >
    > I get exactly what I want in TDate on the called form.
    >
    > But if I remove this from the properties and put the following code in
    > for the called form's open form event, it doesn't work:
    >
    > Me.TDate.Defaul tValue = [Forms]![SelectionFrm]![TDate]
    >
    > I put a stop right after this statement. The value of
    > Me.TDate.Defaul tValue shows correctly at that point. But on the screen
    > it comes up as '12/30/1899'.
    >
    > I also tried putting it in the BeforeUpdate event of TDate. That didn't
    > work either.
    >
    > Any idea why the code doesn't work while the property does? Or is it
    > impossible to set default values in code?
    >
    > Robert
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it![/color]


    Comment

    • Bob Quintal

      #3
      Re: Code to set property in form not working

      Robert C <projecttoday@y ahoo.com> wrote in
      news:40844d9c$0 $201$75868355@n ews.frii.net:
      [color=blue]
      >
      >
      > I have 2 forms, an unbound which calls a bound form via a
      > command button. Both forms have a textbox called TDate. The
      > name of the calling form is SelectionFrm. When I set the
      > DefaultValue property of the textbox on the called form to:
      >
      > =[Forms]![SelectionFrm]![TDate]
      >
      > I get exactly what I want in TDate on the called form.
      >
      > But if I remove this from the properties and put the following
      > code in for the called form's open form event, it doesn't
      > work:
      >
      > Me.TDate.Defaul tValue = [Forms]![SelectionFrm]![TDate]
      >
      > I put a stop right after this statement. The value of
      > Me.TDate.Defaul tValue shows correctly at that point. But on
      > the screen it comes up as '12/30/1899'.
      >
      > I also tried putting it in the BeforeUpdate event of TDate.
      > That didn't work either.
      >
      > Any idea why the code doesn't work while the property does?[/color]

      That's because the code fires after the control has been set on the
      form.
      [color=blue]
      > Or is it impossible to set default values in code?[/color]

      It's pretty well useless to set default values in code. Your form
      will work quite well just setting Me.Tdate.value if you are
      creating a new record.

      Bob Quintal
      [color=blue]
      >
      > Robert
      >
      >
      > *** Sent via Developersdex http://www.developersdex.com ***
      > Don't just participate in USENET...get rewarded for it!
      >[/color]

      Comment

      • Robert

        #4
        Re: Code to set property in form not working

        This works in the current event:

        If Me.NewRecord Then
        Me.TDate.Value = [Forms]![SelectionFrm]![TDate]
        End If

        The DefaultValue works when I put it in on the screen, so why not in code?
        It would be nice to know, anyway, even if the form is working okay now.

        Robert C

        "Bob Quintal" <bquintal@gener ation.net> wrote in message
        news:95dfcadef3 18bb60610d9834f 45b1302@news.te ranews.com...[color=blue]
        > Robert C <projecttoday@y ahoo.com> wrote in
        > news:40844d9c$0 $201$75868355@n ews.frii.net:
        >[color=green]
        > >
        > >
        > > I have 2 forms, an unbound which calls a bound form via a
        > > command button. Both forms have a textbox called TDate. The
        > > name of the calling form is SelectionFrm. When I set the
        > > DefaultValue property of the textbox on the called form to:
        > >
        > > =[Forms]![SelectionFrm]![TDate]
        > >
        > > I get exactly what I want in TDate on the called form.
        > >
        > > But if I remove this from the properties and put the following
        > > code in for the called form's open form event, it doesn't
        > > work:
        > >
        > > Me.TDate.Defaul tValue = [Forms]![SelectionFrm]![TDate]
        > >
        > > I put a stop right after this statement. The value of
        > > Me.TDate.Defaul tValue shows correctly at that point. But on
        > > the screen it comes up as '12/30/1899'.
        > >
        > > I also tried putting it in the BeforeUpdate event of TDate.
        > > That didn't work either.
        > >
        > > Any idea why the code doesn't work while the property does?[/color]
        >
        > That's because the code fires after the control has been set on the
        > form.
        >[color=green]
        > > Or is it impossible to set default values in code?[/color]
        >
        > It's pretty well useless to set default values in code. Your form
        > will work quite well just setting Me.Tdate.value if you are
        > creating a new record.
        >
        > Bob Quintal
        >[color=green]
        > >
        > > Robert
        > >
        > >
        > > *** Sent via Developersdex http://www.developersdex.com ***
        > > Don't just participate in USENET...get rewarded for it!
        > >[/color]
        >[/color]


        Comment

        • Robert

          #5
          Re: Code to set property in form not working

          This produces the same result. I am using a work-around now. Thanks for
          your help.
          Robert
          "Douglas J. Steele" <NOSPAM_djsteel e@NOSPAM_canada .com> wrote in message
          news:BJYgc.4003 1$9kJ.33000@new s04.bloor.is.ne t.cable.rogers. com...[color=blue]
          > The Default Value property is text, regardless of what the value is. Try:
          >
          > Me.TDate.Defaul tValue = "" & [Forms]![SelectionFrm]![TDate] & ""
          >
          > or
          >
          > Me.TDate.Defaul tValue = Chr$(34) & [Forms]![SelectionFrm]![TDate] &[/color]
          Chr$(34)[color=blue]
          >
          >
          > --
          > Doug Steele, Microsoft Access MVP
          > http://I.Am/DougSteele
          > (No private e-mails, please)
          >
          >
          >
          > "Robert C" <projecttoday@y ahoo.com> wrote in message
          > news:40844d9c$0 $201$75868355@n ews.frii.net...[color=green]
          > >
          > >
          > > I have 2 forms, an unbound which calls a bound form via a command
          > > button. Both forms have a textbox called TDate. The name of the
          > > calling form is SelectionFrm. When I set the DefaultValue property of
          > > the textbox on the called form to:
          > >
          > > =[Forms]![SelectionFrm]![TDate]
          > >
          > > I get exactly what I want in TDate on the called form.
          > >
          > > But if I remove this from the properties and put the following code in
          > > for the called form's open form event, it doesn't work:
          > >
          > > Me.TDate.Defaul tValue = [Forms]![SelectionFrm]![TDate]
          > >
          > > I put a stop right after this statement. The value of
          > > Me.TDate.Defaul tValue shows correctly at that point. But on the screen
          > > it comes up as '12/30/1899'.
          > >
          > > I also tried putting it in the BeforeUpdate event of TDate. That didn't
          > > work either.
          > >
          > > Any idea why the code doesn't work while the property does? Or is it
          > > impossible to set default values in code?
          > >
          > > Robert
          > >
          > >
          > > *** Sent via Developersdex http://www.developersdex.com ***
          > > Don't just participate in USENET...get rewarded for it![/color]
          >
          >[/color]


          Comment

          • Bob Quintal

            #6
            Re: Code to set property in form not working

            "Robert" <projecttoday@y ahoo.com> wrote in
            news:108955e5id vojb0@corp.supe rnews.com:
            [color=blue]
            > This works in the current event:
            >
            > If Me.NewRecord Then
            > Me.TDate.Value = [Forms]![SelectionFrm]![TDate]
            > End If
            >
            > The DefaultValue works when I put it in on the screen, so why
            > not in code? It would be nice to know, anyway, even if the
            > form is working okay now.
            >
            > Robert C[/color]

            Think about the sequence of the events that occur when you click on
            the button to open your new form.

            The first thing that happens is that Access opens the form.
            Second it moves to eof,(the new record),
            third thing it does is it fills in the fields from the default
            values,
            Lastly it then execudes your code that changes the default values.

            Everything is working as it should, but it's too late for the
            record shown on the screen.

            That's why I said that changing .defaultvalue in code is pretty
            useless.

            The next new record would show the amended defaultvalue, as long as
            you don't close the form between each addition.

            That's why I didn't say 'totally useless'.

            Bob Q.

            Comment

            • Robert

              #7
              Re: Code to set property in form not working

              Okay, I understand now.

              "Bob Quintal" <bquintal@gener ation.net> wrote in message
              news:b668c6ed9a 2598808f375b4a3 0aa1288@news.te ranews.com...[color=blue]
              > "Robert" <projecttoday@y ahoo.com> wrote in
              > news:108955e5id vojb0@corp.supe rnews.com:
              >[color=green]
              > > This works in the current event:
              > >
              > > If Me.NewRecord Then
              > > Me.TDate.Value = [Forms]![SelectionFrm]![TDate]
              > > End If
              > >
              > > The DefaultValue works when I put it in on the screen, so why
              > > not in code? It would be nice to know, anyway, even if the
              > > form is working okay now.
              > >
              > > Robert C[/color]
              >
              > Think about the sequence of the events that occur when you click on
              > the button to open your new form.
              >
              > The first thing that happens is that Access opens the form.
              > Second it moves to eof,(the new record),
              > third thing it does is it fills in the fields from the default
              > values,
              > Lastly it then execudes your code that changes the default values.
              >
              > Everything is working as it should, but it's too late for the
              > record shown on the screen.
              >
              > That's why I said that changing .defaultvalue in code is pretty
              > useless.
              >
              > The next new record would show the amended defaultvalue, as long as
              > you don't close the form between each addition.
              >
              > That's why I didn't say 'totally useless'.
              >
              > Bob Q.
              >[/color]


              Comment

              Working...