+ Reply to Thread
Results 1 to 20 of 20

Search Edit & Update using the Userform

Hybrid View

  1. #1
    Registered User
    Join Date
    12-06-2020
    Location
    Essex
    MS-Off Ver
    365
    Posts
    29

    Search Edit & Update using the Userform

    I'm looking for some help with code

    I'm new to userforms & vba coding, after some research and reading some of the threads on this forum, i managed to create a Userform with a variety of textbox's, combobox's, option selection, i have three command buttons "Enter Clear Close" all these are working fine.

    My question is, i have created another command buttons to Search, to make edits to a record, i can't seem to get the code right, if i attach my file, can some have a look, please.

    Thanks in advance
    Chris

  2. #2
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: Search Edit & Update using the Userform

    Hi Chris & welcome to the forum,

    Yes, if you post a sample file & indicate exactly what you need to achieve, people will provide you the help required ... Just follow the instructions at the top of the page on how to attach a file

  3. #3
    Registered User
    Join Date
    12-06-2020
    Location
    Essex
    MS-Off Ver
    365
    Posts
    29

    Re: Search Edit & Update using the Userform

    I've attached a slimmed-down version of what I'm trying to achieve, everything is working except the Search & Update command buttons
    Attached Files Attached Files

  4. #4
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: Search Edit & Update using the Userform

    Try below code ... You can add more fields

    Private Sub CommandButton2_Click()
    'update record
    
    Dim Rg As Range
     
    If VinNumber.Value = "" Then
       MsgBox "Please enter the VIN #", vbExclamation
       VinNumber.SetFocus
       Exit Sub
    End If
    
    With Sheets("Stock Table").ListObjects(1).DataBodyRange
       Set Rg = .Columns(1).Find(VinNumber.Value, lookat:=xlWhole)
       If Rg Is Nothing Then
          MsgBox VinNumber.Value & " is not available !", vbExclamation
          Exit Sub
       Else
          Rg.Offset(, 2).Value = VehicleMake.Value
          Rg.Offset(, 4).Value = StockLocation.Value
          Rg.Offset(, 5).Value = GefcoReference.Value
          Rg.Offset(, 12).Value = PodReference.Value
       End If
    End With
    
    End Sub
    
    Private Sub CommandButton3_Click()
    'search button
     
    Dim Rg As Range
     
    If VinNumber.Value = "" Then
       MsgBox "Please enter the VIN #", vbExclamation
       VinNumber.SetFocus
       Exit Sub
    End If
    
    With Sheets("Stock Table").ListObjects(1).DataBodyRange
       Set Rg = .Columns(1).Find(VinNumber.Value, lookat:=xlWhole)
       If Rg Is Nothing Then
          MsgBox VinNumber.Value & " is not available !", vbExclamation
          Exit Sub
       Else
          VehicleMake.Value = Rg.Offset(, 2).Value
          StockLocation.Value = Rg.Offset(, 4).Value
          GefcoReference.Value = Rg.Offset(, 5).Value
          PodReference.Value = Rg.Offset(, 12).Value
       End If
    End With
    
    End Sub
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

  5. #5
    Registered User
    Join Date
    12-06-2020
    Location
    Essex
    MS-Off Ver
    365
    Posts
    29

    Re: Search Edit & Update using the Userform

    Hi nankw83

    Thank you for your code, i am still getting an error? Please see screenshot

  6. #6
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: Search Edit & Update using the Userform

    Quote Originally Posted by Chrisb812 View Post
    Hi nankw83

    Thank you for your code, i am still getting an error? Please see screenshot
    You're getting this error message because there's no sheet called 'Stock Table' like your sample file ... I have attached the file I worked on for your reference
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    12-06-2020
    Location
    Essex
    MS-Off Ver
    365
    Posts
    29

    Re: Search Edit & Update using the Userform

    Quote Originally Posted by nankw83 View Post
    You're getting this error message because there's no sheet called 'Stock Table' like your sample file ... I have attached the file I worked on for your reference
    That's absolutely perfect, i can see it now, thank you so much for your help.

  8. #8
    Registered User
    Join Date
    12-06-2020
    Location
    Essex
    MS-Off Ver
    365
    Posts
    29

    Re: Search Edit & Update using the Userform

    Screenshot (1).png

    Screenshot of message

  9. #9
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,411

    Re: Search Edit & Update using the Userform

    @Chrisb812, alternative approach using table as data storage - all actions as you would need - ADD/SEARCH/UPDATE/REMOVE.
    Note, rather than tedious fill all the labels, leave the defaults and loop through the table headers when initializing the form.
    Also same principal with the textboxes (leave default names and with a single loop populate them and/or store updated info.
    You will see some of the textboxes have a hidden combobox under them for choice from the validation lists.
    any queries - happy to answer.
    torachan.
    Attached Files Attached Files

  10. #10
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: Search Edit & Update using the Userform

    Glad to help

    If that takes care of your request, please take a moment & mark this thread as [SOLVED] from the Thread Tools above your first post & consider * Add Reputation by clicking the star under the usernames of those who have help

  11. #11
    Registered User
    Join Date
    12-06-2020
    Location
    Essex
    MS-Off Ver
    365
    Posts
    29

    Re: Search Edit & Update using the Userform

    Thank you again for all your help, I have one last thing I added a delete button, can you help me with the code to delete the entire row for that record, with a message box with a Yes/No confirmation to delete

  12. #12
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: Search Edit & Update using the Userform

    You can utilize the same code ...

    Private Sub CommandButton4_Click() '<--- ensure the button name is correct
    'delete button
     
    Dim Rg As Range
     
    If VinNumber.Value = "" Then
       MsgBox "Please enter the VIN #", vbExclamation
       VinNumber.SetFocus
       Exit Sub
    End If
    
    With Sheets("Stock Table").ListObjects(1).DataBodyRange
       Set Rg = .Columns(1).Find(VinNumber.Value, lookat:=xlWhole)
       If Rg Is Nothing Then
          MsgBox VinNumber.Value & " is not available !", vbExclamation
          Exit Sub
       Else
          If MsgBox("Delete Row ?", vbYesNo + vbQuestion) = vbYes Then Rg.EntireRow.Delete
       End If
    End With
    
    End Sub

  13. #13
    Registered User
    Join Date
    12-06-2020
    Location
    Essex
    MS-Off Ver
    365
    Posts
    29

    Re: Search Edit & Update using the Userform

    That's perfect, thank you

    I noticed a problem with the code you wrote for the search and update, when I do a search the data returned do not load in the correct fields on the form, and then when i update, the data doesn't update to the correct cells on the sheet. The Enter New macro is working, and sending the correct data to the correct cells, would mind having another look at the code.

    Thanks in advance
    Chris
    Attached Files Attached Files

  14. #14
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: Search Edit & Update using the Userform

    Hi Chris,

    There's no issue with the code itself, you just need to change the mapping based on your cells ... I guess easiest way is just to copy from "Enter New" macro & do the required changes ...

        Rg.Offset(, 1) = VinNumber.Value
        Rg.Offset(, 2) = BARCODE.Value
        Rg.Offset(, 3) = VehicleMake.Value
        Rg.Offset(, 4) = VehicleType.Value
        Rg.Offset(, 5) = StockLocation.Value
        Rg.Offset(, 6) = GefcoReference.Value
        Rg.Offset(, 7) = DateIn.Value
        Rg.Offset(, 8) = DateOut.Value
        Rg.Offset(, 9) = ReceivingDealer.Value
        Rg.Offset(, 11) = PodDate.Value
        Rg.Offset(, 12) = PodReference.Value
        Rg.Offset(, 13) = Notes.Value

  15. #15
    Registered User
    Join Date
    12-06-2020
    Location
    Essex
    MS-Off Ver
    365
    Posts
    29

    Re: Search Edit & Update using the Userform

    I tried that, still didn't map to the right fields.
    here a pic of the result and search mapScreenshot (6).png
    .
    .

  16. #16
    Registered User
    Join Date
    12-06-2020
    Location
    Essex
    MS-Off Ver
    365
    Posts
    29

    Re: Search Edit & Update using the Userform

    The maping
    Attached Images Attached Images

  17. #17
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: Search Edit & Update using the Userform

    Are all fields shifted by 1 column ? If yes, try to reduce the .offset(,x) by 1 ... The Rg is starting from the first column of your table not the first column of the sheet

  18. #18
    Registered User
    Join Date
    12-06-2020
    Location
    Essex
    MS-Off Ver
    365
    Posts
    29

    Re: Search Edit & Update using the Userform

    They seem to be -1, column 3 is in 2, 4 is in 3, .... and so on

  19. #19
    Registered User
    Join Date
    12-06-2020
    Location
    Essex
    MS-Off Ver
    365
    Posts
    29

    Re: Search Edit & Update using the Userform

    @nanwk83
    That seems to have done the trick, column 1=0 and 2=1 and so ........ but all good now.

    Thank you again
    Chris

  20. #20
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: Search Edit & Update using the Userform

    Glad to help & thanks for reporting back

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. (SOLVED) Please add Search / Edit and Update Button
    By Stona in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-25-2020, 09:54 AM
  2. [SOLVED] VBA Userform - Search, Edit & Update functionality
    By motokaxperts in forum Excel Programming / VBA / Macros
    Replies: 71
    Last Post: 06-21-2019, 12:58 PM
  3. [SOLVED] Userform - Search, Edit & Update
    By nancyching1711 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 03-09-2018, 05:34 AM
  4. USERFORM : Search and edit data in userform
    By mohit.kumar9094 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2018, 07:50 AM
  5. [SOLVED] VBA Userform - Search, Edit & Update functionality
    By camp2chiawa in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-15-2016, 03:43 AM
  6. [SOLVED] VBA Userform Edit/Update record help
    By sa.1985 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-20-2013, 10:29 AM
  7. update value and edit items already update on sheet by userform
    By tjxc32m in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-08-2013, 10:13 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1