Hello everyone,


I have a Userform to display data/reocord from my Sheet 1 (name " Main") and Sheet 2 (name " Payment Records").

In the Userform there are 10 TextBoxes which show data from Sheet 1 and in the same userform there is also a list box which show data/record from Sheet 2.

In the user form I have two command buttons ( commandbutton 1 & commandbutton2)

In the userform if I press commandbutton1 it shows me records from my Sheet2 and If I press commandbutton 2 it shows me record from Sheet1.

Everything is working perfectly....It shows me every data from Sheet1 & Sheet2 which I need.


The problem is what I want is that there should be Only ONE command button on the userform to display record for both sheets.

I do not want 2 command buttons. I want when I press one commandbutton1 it should show me data from both sheet.

I do not want any other changes in displaying data....I just want One CommandButton.


Here are my two seperate codes for both sheets on a single UserForm.

Private Sub CommandButton1_Click()
  'SHOW RECORD
    
    Dim FoundIt     As Range
    Dim Id          As Double
    Dim Rng         As Range
    Dim StartAddx   As String
    Dim Wks         As Worksheet
    
    
        Set Wks = Worksheets("Payment Records")
    
        Id = Val(TextBoxEnrollmentNumber.Value)
        
        Set Rng = Wks.Range("A9").CurrentRegion.Columns(2).Cells
        
        Set FoundIt = Rng.Find(Id, , xlValues, xlWhole, xlByRows, xlNext, False, False, False)
        
        If FoundIt Is Nothing Then
            MsgBox "ID '" & Id & "' was Not Found."
            Exit Sub
        End If
        
            StartAddx = FoundIt.Address
            
            ListBox1.Clear
            
            Do
                Row = FoundIt.Row
                With ListBox1
                    .AddItem
                    .List(.ListCount - 1, 0) = Cells(Row, "H").Text
                    .List(.ListCount - 1, 1) = Cells(Row, "J").Text
                    .List(.ListCount - 1, 2) = Cells(Row, "K").Text
                    .List(.ListCount - 1, 3) = Cells(Row, "I").Text
                End With
                Set FoundIt = Rng.FindNext(FoundIt)
                If FoundIt Is Nothing Then Exit Do
                If FoundIt.Address = StartAddx Then Exit Do
            Loop
            
End Sub

Private Sub UserForm_Initialize()

    Dim ColumnWidths As String
    
        With ListBox1
            .ColumnCount = 4
            ColumnWidths = "118;50;85"
            .ColumnWidths = ColumnWidths
        End With
    
End Sub

Private Sub CommandButton2_click()

Dim sFind As String, rFound As Range


    If Me.TextBoxEnrollmentNumber = vbNullString Then Exit Sub
    sFind = Me.TextBoxEnrollmentNumber.Value
    
   'Match Invoice Number and dispaly Detail
    
    'after:=.Cells(1, 2)  1=row number, 2=coloumn number
    
    
    With Sheet1
        Set rFound = .Columns("B:B").Find(what:=sFind, after:=.Cells(9, 2), LookIn:=xlValues, lookat:=xlWhole, _
            searchorder:=xlByRows, searchdirection:=xlNext)
            
            
        If Not rFound Is Nothing Then
            With Me
            
            '.TextBox2 = rFound.Offset(0, -1)  -1 = column number
                
                .TextBoxStudent = rFound.Offset(0, 1)
                .TextBoxFather = rFound.Offset(0, 9)
                .TextBoxDateOFBirth = rFound.Offset(0, 11)
                .TextBoxContactNo = rFound.Offset(0, 12)
                .TextBoxAddress = rFound.Offset(0, 13)
                .TextBoxDateAddmission = rFound.Offset(0, -1)
                .TextBoxEnrolledFor = rFound.Offset(0, 2)
                .TextBoxTotalfees = rFound.Offset(0, 4)
                .TextBoxAmountreceived = rFound.Offset(0, 5)
                .TextBoxFeesdue = rFound.Offset(0, 6)
                
                
                


 
            End With
        Else
            MsgBox "No Record Found"
        End If
    End With

End Sub

I hope you guys will be understanding what I mean...

I will be very thankful..If any one could help me