Results 1 to 12 of 12
  1. #1
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253

    Adding hours and minutes to a time entered in a text box

    I was trying to do something very basic but I keep getting the error: member already exists in an object module from which this object derives. here is all of the code in this form.

    Code:
    Option Compare Database
    Option Explicit
    Dim Text0 As Date
    Dim text1 As Date
    Private Sub btnCalcTimes_Click()
        text1 = DateAdd("n", 6, "Test0")
    End Sub
    Currently on this form there are 2 txt boxes and one button. The form is new and not attached to anything else.

    Could someone please help me with this code and possible explain why I get that error. I have been googling it and I haven't understood the answers for the error.

    Thank you,


    Walker

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Are you naming variables the same as the textboxes? You shouldn't.

    I'd also point out that you've got "text0" and then "test0".
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    Thanks Paul I didn't even catch that I have the variables as the txtboxes

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Also, you are trying to add 6 minutes to a text string - shouldn't have the quotes around Text0.

    Had to change the code to :
    Code:
    Private Sub btnCalcTimes_Click()
        '   Dim Text0 As Date
        '   Dim text1 As Date
        Me.Text1 = DateAdd("n", 6, Me.Text0)
    End Sub

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Quote Originally Posted by NightWalker View Post
    Thanks Paul I didn't even catch that I have the variables as the txtboxes
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    Steve thank you that's the piece I was missing. Everything I was getting on google was about adding to a field in which the [] would be used so I thought "" were needed for the text box info.

    Thank you very much

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Echoing Paul..... Happy to help....

  8. #8
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    I have it figured out but is there a way that you all would shorten up this code?

    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub btnCalcTimes_Click()
        Me.txt1 = Me.txt0
        If fraPick.Value = 1 Then
            Me.txt11.Visible = True
            Me.txt12.Visible = True
            Me.txt13.Visible = True
            Me.txt14.Visible = True
            Me.txt15.Visible = True
            Me.txt16.Visible = True
            Me.txt17.Visible = True
            Me.txt18.Visible = True
            Me.txt19.Visible = True
            Me.txt2 = DateAdd("n", 16, Me.txt1)
            Me.txt3 = DateAdd("n", 16, Me.txt2)
            Me.txt4 = DateAdd("n", 16, Me.txt3)
            Me.txt5 = DateAdd("n", 16, Me.txt4)
            Me.txt6 = DateAdd("n", 16, Me.txt5)
            Me.txt7 = DateAdd("n", 16, Me.txt6)
            Me.txt8 = DateAdd("n", 16, Me.txt7)
            Me.txt9 = DateAdd("n", 16, Me.txt8)
            Me.txt10 = DateAdd("n", 16, Me.txt9)
            Me.txt11 = DateAdd("n", 16, Me.txt10)
            Me.txt12 = DateAdd("n", 16, Me.txt11)
            Me.txt13 = DateAdd("n", 16, Me.txt12)
            Me.txt14 = DateAdd("n", 16, Me.txt13)
            Me.txt15 = DateAdd("n", 16, Me.txt14)
            Me.txt16 = DateAdd("n", 16, Me.txt15)
            Me.txt17 = DateAdd("n", 16, Me.txt16)
            Me.txt18 = DateAdd("n", 16, Me.txt17)
            Me.txt19 = DateAdd("n", 16, Me.txt18)
        Else
            Me.txt2 = DateAdd("n", 61, Me.txt1)
            Me.txt3 = DateAdd("n", 6, Me.txt2)
            Me.txt4 = DateAdd("n", 6, Me.txt3)
            Me.txt5 = DateAdd("n", 6, Me.txt4)
            Me.txt6 = DateAdd("n", 6, Me.txt5)
            Me.txt7 = DateAdd("n", 6, Me.txt6)
            Me.txt8 = DateAdd("n", 15, Me.txt7)
            Me.txt9 = DateAdd("n", 130, Me.txt8)
            Me.txt10 = DateAdd("n", 6, Me.txt9)
            Me.txt11.Visible = False
            Me.txt12.Visible = False
            Me.txt13.Visible = False
            Me.txt14.Visible = False
            Me.txt15.Visible = False
            Me.txt16.Visible = False
            Me.txt17.Visible = False
            Me.txt18.Visible = False
            Me.txt19.Visible = False
            
        End If
    End Sub

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Not necessarily faster....... . but shorter!

    See http://access.mvps.org/access/forms/frm0003.htm
    Code:
    Private Sub btnCalcTimes_Click()
        Dim i As Integer
    
        Me.txt1 = Me.txt0
    
        If Me.fraPick = 1 Then
            For i = 11 To 19
                Me("txt" & i) = True
            Next i
                      
            For i = 2 To 19
                Me("txt" & i) = DateAdd("n", 16, Me("txt" & (i - 1)))
            Next i
        Else
            For i = 2 To 10
                Me("txt" & i) = DateAdd("n", 6, Me("txt" & (i - 1)))
            Next i
    
            For i = 11 To 19
                Me("txt" & i) = False
            Next i
        
        End If
    End Sub
    Last edited by ssanfu; 12-09-2016 at 06:25 PM. Reason: corrected the text box name

  10. #10
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    Steve,

    Is there a way that I can put the number of minutes in some type of table that would make this more versatile? It would be based on each product that I am testing. Many of the items have different times and different numbers of times. this program is just for one product and 2 different tests for this product. Any help would be appreciated. If there is not a way I will just have to write code and a form for each Item. That would not be a problem but I am trying to learn ways to shorten my code and have fewer forms when possible. The reason for doing this is to have a more professional looking DB for my customers. Thank you for all your help.

  11. #11
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    If these values are contants then it is best to store them on a table as you say. Which table to store them on depends on which values they apply to: if they apply only to products then put them on the products table, if they apply to products plus something else then put them on that table. Or make a new table cross-referencing the key fields.

  12. #12
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    Yes the values for each product test are constants. I think I will build a new table just for these test times. Thank you very much.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 08-30-2015, 05:17 AM
  2. Replies: 12
    Last Post: 07-19-2015, 05:21 PM
  3. convert hours into minutes
    By princess12 in forum Access
    Replies: 5
    Last Post: 04-13-2015, 01:12 PM
  4. Replies: 4
    Last Post: 06-12-2013, 10:20 AM
  5. Replies: 4
    Last Post: 08-06-2012, 10:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums