Results 1 to 11 of 11
  1. #1
    choruscby is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    4

    I want to make two codes into one code.

    I have attached a file.



    there are two buttons.

    I want to make two(1st code & 2nd code)codes into one code.


    Attached Thumbnails Attached Thumbnails 20211226_145109.jpg  
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,649
    When posting code, please place between CODE tags - the # icon on post edit menu bar.

    What do you mean by "join code"? The procedures are in button click events in your db. What do you want different?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    choruscby is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    4
    sorry revised my question

  4. #4
    choruscby is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    4
    sorry.I have attached file
    There are two codes that 1st code and 2nd code
    I want to make them into one code

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,298
    I think you deleted it ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,649
    The initial post may have been somehow flagged for review and so is not visible to us. Hopefully, a moderator will clear it soon.

    I still don't understand what you want. If you want all the code in one procedure - such as one button click event - then copy/paste the code into one.

    Why do you want it all in one?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,298
    Very misleading then. As your first reply is #1 ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,649
    I didn't think posts could be deleted by anyone except moderators and management.

    Maybe the post numbering means the OP is really gone, I am not sure.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,298
    No idea TBH, but it would be better (to me at least) if it became hidden, like when you ignore a member?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    I approved the post. Hope it helps. There is so little info about the application or what business it is intended to support.

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,298
    Quote Originally Posted by orange View Post
    I approved the post. Hope it helps. There is so little info about the application or what business it is intended to support.
    Ah the O/P changed it to an attachment that explains it.

    At a quick glance, I would say yes, as mot of the code appears to be duplicated?
    So work up to where and from where it is not duplicated line by line and then compare each section in between?
    Put each code block into a notepad window and compare side by side.

    Also indenting it better/correctly would really help?

    Code:
    Private Sub Command2_Click()
        Dim strSQL As String
        Dim rs As DAO.Recordset
        Dim rstT As DAO.Recordset
        Dim i As Long
        Dim PackageCountPan As Long
        Dim NextPackageCountPan As Long
    
    
    
    
        strSQL = "SELECT ERP_QOP_Query_T_TEMP.yearn FROM ERP_QOP_Query_T_TEMP GROUP BY ERP_QOP_Query_T_TEMP.yearn;"
    
    
        Set rs = CurrentDb.OpenRecordset(strSQL)
        rs.MoveFirst
        Do
    
    
            PackageCountPan = Nz(DLookup("panel", "ERP_QOP", "yearn='" & rs!YearN & "'"), 0)
    
    
            If PackageCountPan = 0 Then
                strSQL = "select * from ERP_QOP_Query_T_TEMP where yearn='" & rs!YearN & "'"
                Set rstT = CurrentDb.OpenRecordset(strSQL)
                i = 0
                rstT.MoveFirst
                Do
                    i = i + 1
                    rstT.Edit
    
    
                    rstT!panelCn = 0
                    rstT!panelF = 0
                    rstT!panelNF = rstT!Expcs
                    rstT!YearNcnt = i
    
    
                    rstT.Update
    
    
                    rstT.MoveNext
                Loop Until rstT.EOF
    
    
                GoTo NextPO
    
    
            End If
    
    
            NextPackageCountPan = PackageCountPan
            strSQL = "SELECT * FROM ERP_QOP_Query_T_TEMP where yearn='" & rs!YearN & "'"
            Set rstT = CurrentDb.OpenRecordset(strSQL)
            i = 0
            Do
                i = i + 1
                rstT.Edit
    
    
                rstT!YearNcnt = i
    
    
                If PackageCountPan > 0 Then
                    rstT!panelCn = PackageCountPan
                End If
    
    
    
    
                If NextPackageCountPan = 0 Then
                    rstT!panelNF = rstT!Expcs
                Else
    
    
                    If rstT!Expcs < NextPackageCountPan Then
                        rstT!panelNF = 0
                        rstT!panelF = rstT!Expcs
                        NextPackageCountPan = NextPackageCountPan - rstT!Expcs
    
    
                    ElseIf rstT!Expcs = NextPackageCountPan Then
                        rstT!panelF = rstT!Expcs
                        rstT!panelNF = 0
    
    
                        NextPackageCountPan = 0
    
    
                    ElseIf rstT!Expcs > NextPackageCountPan Then
                        rstT!panelF = NextPackageCountPan
                        rstT!panelNF = rstT!Expcs - NextPackageCountPan
    
    
                        NextPackageCountPan = 0
                    End If
                End If
                PackageCountPan = 0
    
    
    
    
                rstT.Update
                rstT.MoveNext
            Loop Until rstT.EOF
    
    
    NextPO:
            rs.MoveNext
        Loop Until rs.EOF
    
    
        Me.ERP_QOP_Query_T_TEMP_sub.Requery
    End Sub
    
    
    
    
    Private Sub Command5_Click()
    Dim strSQL As String
    Dim rs As DAO.Recordset
    Dim rstT As DAO.Recordset
    Dim i As Long
    Dim PackageCount As Long
    Dim NextPackageCount As Long
    
    
    
    
    strSQL = "SELECT ERP_QOP_Query_T_TEMP.yearn FROM ERP_QOP_Query_T_TEMP GROUP BY ERP_QOP_Query_T_TEMP.yearn;"
    
    
    Set rs = CurrentDb.OpenRecordset(strSQL)
    rs.MoveFirst
    Do
      
      PackageCount = Nz(DLookup("Cutting", "ERP_QOP", "yearn='" & rs!YearN & "'"), 0)
      
      If PackageCount = 0 Then
       strSQL = "select * from ERP_QOP_Query_T_TEMP where yearn='" & rs!YearN & "'"
       Set rstT = CurrentDb.OpenRecordset(strSQL)
       i = 0
       rstT.MoveFirst
       Do
        i = i + 1
        rstT.Edit
       
        rstT!CuttingCn = 0
        rstT!CuttingF = 0
        rstT!CuttingNF = rstT!Expcs
        rstT!YearNcnt = i
       
      rstT.Update
        
      rstT.MoveNext
      Loop Until rstT.EOF
      
      GoTo NextPO
      
    End If
     
     NextPackageCount = PackageCount
     strSQL = "SELECT * FROM ERP_QOP_Query_T_TEMP where yearn='" & rs!YearN & "'"
     Set rstT = CurrentDb.OpenRecordset(strSQL)
     i = 0
     Do
     i = i + 1
       rstT.Edit
         
         rstT!YearNcnt = i
     
         If PackageCount > 0 Then
         rstT!CuttingCn = PackageCount
         End If
        
         
         If NextPackageCount = 0 Then
          rstT!CuttingNF = rstT!Expcs
           Else
           
           If rstT!Expcs < NextPackageCount Then
              rstT!CuttingNF = 0
              rstT!CuttingF = rstT!Expcs
              NextPackageCount = NextPackageCount - rstT!Expcs
              
            ElseIf rstT!Expcs = NextPackageCount Then
              rstT!CuttingF = rstT!Expcs
              rstT!CuttingNF = 0
              
              NextPackageCount = 0
            
            ElseIf rstT!Expcs > NextPackageCount Then
             rstT!CuttingF = NextPackageCount
            rstT!CuttingNF = rstT!Expcs - NextPackageCount
            
            NextPackageCount = 0
            End If
        End If
        PackageCount = 0
        
       
        rstT.Update
    rstT.MoveNext
    Loop Until rstT.EOF
    
    
    NextPO:
    rs.MoveNext
    Loop Until rs.EOF
    
    
    Me.ERP_QOP_Query_T_TEMP_sub.Requery
    End Sub
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Code to populate Join Tables
    By DenisM in forum Programming
    Replies: 4
    Last Post: 06-26-2019, 01:32 AM
  2. Replies: 12
    Last Post: 02-21-2017, 08:33 PM
  3. Replies: 3
    Last Post: 10-16-2014, 08:49 AM
  4. Replies: 1
    Last Post: 05-04-2013, 12:19 PM
  5. Query Join, Expression, or Code
    By catguy in forum Queries
    Replies: 1
    Last Post: 08-17-2011, 10:52 PM

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