setting default values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jacc14
    New Member
    • Jun 2007
    • 116

    setting default values

    I am working on setting a default time when a form is opened.

    Code:
    DoCmd.GoToRecord acActiveDataObject, , acLast
    
    Start_Time.DefaultValue = """" & DateAdd("n", 0, Me.PlannedfinishTimesplit) & """"
    This is working as it should but i have set a bound text box to select a different machine to get a different list. When a different list is selected it still picks up the default time from the previous sheet. I thought it would work if i set the code on the afterupdate for the machine but it kicks up errors. Could anyone help. I have attached the database to explain.

    Thanks
    jacc14
    Attached Files
  • Jerry Maiapu
    Contributor
    • Feb 2010
    • 259

    #2
    Try on the On_Current event. I am just wondering if Start_Time is a control on the form. Because I do not see any control with that name in the forms. I think there is a Start Time control on the sub form.

    If the the control is in the sub-form try in the On_Current event of the sub-form.

    Comment

    • nico5038
      Recognized Expert Specialist
      • Nov 2006
      • 3080

      #3
      Dear jacc14,

      Using a query based on three tables for a subform is asking for trouble as it might turn the subform into a "non-update" state. Best to use "plain" tables as rowsource.

      The default value for a starttime is best set in the corresponding table, thus Access will put it there when a row is added, regardless or you're appending a row in the table directly or using a form.

      Nic;o)

      Comment

      • jacc14
        New Member
        • Jun 2007
        • 116

        #4
        Originally posted by Jerry Maiapu
        Try on the On_Current event. I am just wondering if Start_Time is a control on the form. Because I do not see any control with that name in the forms. I think there is a Start Time control on the sub form.

        If the the control is in the sub-form try in the On_Current event of the sub-form.
        Hi Jerry. You are right the Start_time is a control on the form. I have tried your suggestion with OnCurrent and success.
        Thank you so much

        Jacc14

        Comment

        • jacc14
          New Member
          • Jun 2007
          • 116

          #5
          Originally posted by jacc14
          I am working on setting a default time when a form is opened.

          Code:
          DoCmd.GoToRecord acActiveDataObject, , acLast
          
          Start_Time.DefaultValue = """" & DateAdd("n", 0, Me.PlannedfinishTimesplit) & """"
          This is working as it should but i have set a bound text box to select a different machine to get a different list. When a different list is selected it still picks up the default time from the previous sheet. I thought it would work if i set the code on the afterupdate for the machine but it kicks up errors. Could anyone help. I have attached the database to explain.

          Thanks
          jacc14
          Hello Jerry. I think i spoke too soon. I have put the following code on current :-
          Code:
          Start_Time.DefaultValue = """" & DateAdd("n", 0, Me.PlannedfinishTimesplit) & """"
          This works but the moment I start to enter a new line it just blanks out the defaultvalue as its looking at the current line. I basically want to set it and it then not change again if I move around the form.

          Any ideas please
          Thanks
          Jacc14


          ps on a different approach I have tried the following

          Code:
           Private Sub machine_AfterUpdate()
          Me.Requery
          
          With Me.[Qry_sections_subform]
          .SetFocus
          .Form![Job no].SetFocus
          End With
          DoCmd.GoToRecord acActiveDataObject, , acLast
          
          
          Start_Time.DefaultValue = """" & DateAdd("n", 0, Me.PlannedfinishTimesplit) & """"
          
          
          End Sub
          The idea is that when the machine is changed it then goes to the last record in the subform and applies the defaultvalue. However it returns OBJECT NOT SET. I am confused as when I set the default value ON LOAD of the subform it works perfect but as soon as I change the machine it just retains the original value from the first page. Its as if I need to do it on RELOAD.
          Last edited by jacc14; Jul 8 '10, 07:52 PM. Reason: added another idea

          Comment

          • Jerry Maiapu
            Contributor
            • Feb 2010
            • 259

            #6
            Ok am busy right now tell me Start_Time is on the sub-form or parent. I'll go through test it and come back later.

            Ta..

            Comment

            • jacc14
              New Member
              • Jun 2007
              • 116

              #7
              Hi Jerry. Yes the Start_time is in the sub form
              best regards
              Chris

              Comment

              • Jerry Maiapu
                Contributor
                • Feb 2010
                • 259

                #8
                See suggestion

                Comment

                • Jerry Maiapu
                  Contributor
                  • Feb 2010
                  • 259

                  #9
                  Hi Chris, I am sorry.. I was quite busy and almost forget.

                  Now, the problem you seem to face I guess is because of the fact that you want to set a default value in[Start Time] based on the value of the last record in one of you columns[PlannedfinishTi mesplit].

                  Well, remember that PlannedfinishTi mesplit will have many value list and to pick the desired value will be quite unpredictable.

                  If you look at the behavior you'll see that whenever you place the cursor in one of the field values of PlannedfinishTi mesplit,the current value will change as default on the Start_Time .

                  I think what you should do is use First/Last function to get the last value for PlannedfinishTi mesplit on the subform footer and set this as the default value for Start_Time and fire it on the On_Current event of the child form.

                  And also remove this portion of the code you placed on onload event of the subform:

                  Code:
                  Start_Time.DefaultValue = """" & DateAdd("n", 0, Me.PlannedfinishTimesplit) & """"
                  and instead put on On_Current event like I posted earlier.

                  Cheers

                  Comment

                  • jacc14
                    New Member
                    • Jun 2007
                    • 116

                    #10
                    Hi Jerry. thanks for taking the time. I can work with this.

                    Cheers
                    Chris

                    Comment

                    Working...