• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Userform Update VBA code not working after search result

arihan1511

New Member
Good Evening Members
I am Building a user form to store my contacts.By using the user form I can edit,search,view previous or next contact or add new contact
There is a command button "Add" which on clicking updates sheet with any modification made on user form.This Button works beautifully when record is viewed and modified using next or previous button.
For 10-15 contacts navigating through contacts is possible but for large no of contacts a search function is created using combobox1 change event function.
But the moment I search contact using Combobox1 and then try to update sheet with modification made in the found contact ,"Add" button fails to update the Sheet. In fact Add button neither works nor shows any error after search procedure using combobox 1 and Userform has to be restarted to update any contacts
I am stuck up at this stage

Code:
Private Sub Add_Click()

Worksheets("OPD").AutoFilterMode = False

Dim FoundCell As Range
    Dim Search As String

    Search = VisitDate.Value

    Set FoundCell = Sheets("OPD").Columns(1).Find(Search, _
                                                    LookIn:=xlValues, _
                                                    LookAt:=xlWhole)
If FoundCell Is Nothing Then
MsgBox "No Record Found in Database", vbInformation, "Contacts"
    Exit Sub
    Else
    'Dim lastrow As Long
FoundCell.Select
UpdateData

MsgBox "Record Updated in Database", vbInformation, "Contacts"
ActiveWorkbook.Save
End If

End Sub

Code:
Private Sub ComboBox1_Change()

Worksheets("OPD").AutoFilterMode = False

Dim FoundCell As Range
    Dim Search As String

    Search = ComboBox1.Value

    Set FoundCell = Sheets("OPD").Columns(1).Find(Search, _
                                                    LookIn:=xlValues)
                                               
    If FoundCell Is Nothing Then
MsgBox "No Record Found in Database", vbInformation, "Contacts"
    Exit Sub
    Else
    'Dim lastrow As Long
FoundCell.Select
GetData

TotalRec.Value = Range(Columns("A:A").SpecialCells(xlCellTypeVisible).Address).SpecialCells(xlCellTypeConstants, 3).Count - 1
End If
End Sub

Can anyone Guide me where I have gone wrong, why Add button stops working after running search VBA change event using Combobox1?
Any help in this regard will be appreciable......
Attached file for reference
For Privacy Issue Name and No have been modified
 

Attachments

  • Contact.xlsm
    119.6 KB · Views: 18
Hi !

Find function not works with value but with display specially for real date
(as numeric not string) so try with Text instead of Value if VisitDate
is a Range … If not, search value within Find must be formated the same
as cells (use Format text function) …
 
Back
Top