VBA Issue with Searching on a form

JayDogUK

New Member
Joined
Feb 11, 2023
Messages
9
Office Version
  1. 365
Platform
  1. Windows
I have created a form because there are 1000's of details that are going to be inputted.
As you can see below i am searching for a PO NUMBER which is in the spreadsheet.
But it has come back saying it can not find a record.
ScreenShot1.png

Below is the VBA Coding in the module1
VBA Code:
Option Explicit
Public EnableEvents As Boolean

Private Sub cmbSearchColumn_Change()

    If Me.EnableEvents = False Then Exit Sub
    
    If Me.cmbSearchColumn.Value = "All" Then
    
        Call Reset
    Else
    
        Me.txtSearch.Value = ""
        Me.txtSearch.Enabled = True
        Me.cmdSearch.Enabled = True
    
    End If


End Sub


Private Sub cmdDelete_Click()

    Dim Irow As Long

    If selected_list = 0 Then
    
        MsgBox "No row is selected.", vbOKOnly + vbInformation, "Delete"
        Exit Sub
        
    End If
    
    Dim i As VbMsgBoxResult
    
    i = MsgBox("Do you want to delete the selected record?", vbYesNo + vbQuestion, "confirmation")
    
    If i = vbNo Then Exit Sub
    
    Irow = Application.WorksheetFunction.Match(Me.lstDatabase.List(Me.lstDatabase.ListIndex, 0), _
    ThisWorkbook.Sheets("PODatabase").Range("A:A"), 0)
    
    ThisWorkbook.Sheets("PODatabase").Rows(Irow).Delete
    
    Call Reset
    
    MsgBox "Selected record has been deleted.", vbOKOnly + vbInformation, "Deleted"


End Sub

Private Sub cmdEdit_Click()

    If selected_list = 0 Then
    
    MsgBox "No Row Selected", vbOKOnly + vbInformation, "Edit"
    
    Exit Sub
    
End If

    Me.txtRowNumber.Value = Application.WorksheetFunction.Match(Me.lstDatabase.List(Me.lstDatabase.ListIndex, 0), _
    ThisWorkbook.Sheets("Database").Range("a:A"), 0)
    
    Me.cmbCompany.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 1)
    
    Me.cmbtype.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 2)
    
    Me.txtName.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 3)
    
    Me.txtNHS.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 4)
      
    Me.txtpostcode.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 5)
    
    Me.cmbCCG.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 6)
    
    Me.txtReqNo.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 7)
    
    Me.txtPONO.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 8)
    
    MsgBox "Please Make the required changes and click on 'Save' button to update.", vbOKOnly + vbInformation, "Edit"
    

End Sub

Private Sub cmdFullScreen_Click()

    Call Maximize_Restore

End Sub

Private Sub cmdReset_Click()

    Dim msgValue As VbMsgBoxResult
    
    msgValue = MsgBox("Do you want to reset the form?", vbYesNo + vbInformation, "Comfirmation")
    
    If msgValue = vbNo Then Exit Sub

    Call Reset
    
End Sub

Private Sub cmdSave_Click()
 
    Dim msgValue As VbMsgBoxResult
    
    msgValue = MsgBox("Do you want to save the data?", vbYesNo + vbInformation, "Comfirmation")
    
    If msgValue = vbNo Then Exit Sub

    Call Submit
    Call Reset
    
    
End Sub


Private Sub cmdSearch_Click()

    If Me.txtSearch.Value = "" Then
    
        MsgBox "Please enter the search value.", vbOKOnly + vbInformation, "search"
        Exit Sub
        
        End If

        Call SearchData
        
End Sub


Private Sub UserForm_Initialize()
 
    Call Reset
    
End Sub

Rich (BB code):
Option Explicit
Public EnableEvents As Boolean

Private Sub cmbSearchColumn_Change()

    If Me.EnableEvents = False Then Exit Sub
    
    If Me.cmbSearchColumn.Value = "All" Then
    
        Call Reset
    Else
    
        Me.txtSearch.Value = ""
        Me.txtSearch.Enabled = True
        Me.cmdSearch.Enabled = True
    
    End If


End Sub


Private Sub cmdDelete_Click()

    Dim Irow As Long

    If selected_list = 0 Then
    
        MsgBox "No row is selected.", vbOKOnly + vbInformation, "Delete"
        Exit Sub
        
    End If
    
    Dim i As VbMsgBoxResult
    
    i = MsgBox("Do you want to delete the selected record?", vbYesNo + vbQuestion, "confirmation")
    
    If i = vbNo Then Exit Sub
    
    Irow = Application.WorksheetFunction.Match(Me.lstDatabase.List(Me.lstDatabase.ListIndex, 0), _
    ThisWorkbook.Sheets("PODatabase").Range("A:A"), 0)
    
    ThisWorkbook.Sheets("PODatabase").Rows(Irow).Delete
    
    Call Reset
    
    MsgBox "Selected record has been deleted.", vbOKOnly + vbInformation, "Deleted"


End Sub

Private Sub cmdEdit_Click()

    If selected_list = 0 Then
    
    MsgBox "No Row Selected", vbOKOnly + vbInformation, "Edit"
    
    Exit Sub
    
End If

    Me.txtRowNumber.Value = Application.WorksheetFunction.Match(Me.lstDatabase.List(Me.lstDatabase.ListIndex, 0), _
    ThisWorkbook.Sheets("Database").Range("a:A"), 0)
    
    Me.cmbCompany.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 1)
    
    Me.cmbtype.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 2)
    
    Me.txtName.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 3)
    
    Me.txtNHS.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 4)
      
    Me.txtpostcode.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 5)
    
    Me.cmbCCG.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 6)
    
    Me.txtReqNo.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 7)
    
    Me.txtPONO.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 8)
    
    MsgBox "Please Make the required changes and click on 'Save' button to update.", vbOKOnly + vbInformation, "Edit"
     

End Sub

Private Sub cmdFullScreen_Click()

    Call Maximize_Restore

End Sub

Private Sub cmdReset_Click()

    Dim msgValue As VbMsgBoxResult
    
    msgValue = MsgBox("Do you want to reset the form?", vbYesNo + vbInformation, "Comfirmation")
    
    If msgValue = vbNo Then Exit Sub

    Call Reset
    
End Sub

Private Sub cmdSave_Click()
 
    Dim msgValue As VbMsgBoxResult
    
    msgValue = MsgBox("Do you want to save the data?", vbYesNo + vbInformation, "Comfirmation")
    
    If msgValue = vbNo Then Exit Sub

    Call Submit
    Call Reset
    
    
End Sub


Private Sub cmdSearch_Click()

    If Me.txtSearch.Value = "" Then
    
        MsgBox "Please enter the search value.", vbOKOnly + vbInformation, "search"
        Exit Sub
        
        End If

        Call SearchData
        
End Sub


Private Sub UserForm_Initialize()
 
    Call Reset
    
End Sub

If anyone could help me solve this issue I will be truly grateful and also this will form / excel form will help out many children within the healthcare sector.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Still not having any luck...
Thank you for suggesting ideas

Hi,
with a complex project it would be more helpful to forum if you placed a copy of your workbook with dummy data on a file sharing site like dropbox & provide a link to it. Someone here may then rise to the challenge to help you resolve the issue.

Dave
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,187
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top