VBA User Forms videos | Excel VBA Forms Pt 17 - Editing Data

Posted by Andrew Gould on 18 April 2016

User forms aren't just for data entry; you can use them to edit and delete data too! This video explains how to create a form which allows the user to browse a set of records held in a worksheet and to edit and delete that data using the form. Along the way, you'll learn about a couple of advanced programming techniques such as declaring Enumerations and Property statements.

You can download any files that you need to follow the video here.

You can increase the size of the video:

Full screen mode for YouTube

You can view the video in full screen mode as shown on the left, using the icon at the bottom right of the frame.

You can also increase the quality of the video:

Changing resolution

You can improve the resolution of the video using another icon at the bottom right of the frame. This will slow down the connection speed, but increase the display and sound quality. This icon only becomes visible when you start playing the video.

Finally, if nothing happens when you play the video, check that you're not using IE in compatibility view.

This page has 2 threads Add post
01 Oct 18 at 16:23

Andrew,

 

Many thanks for the response. On a quick first read it looks as if that is exactly what I need and looks to be simpler and more elegant than the changes I was planning to make.

I am currently sitting on a boat in Croatia so I won’t get a chance to give this a try until I am back home, but I will do so as soon as I can.  I hope that revisiting past code did not take up too much of your valuable time.

Once again many thanks,

regards,

Colin Murdoch

02 Oct 18 at 07:42

You're most welcome Colin!  It's nice to know that the videos are still being used years after they were published.  Enjoy Croatia!

26 Sep 18 at 13:27

Andrew,

Many thanks for all the excellent videos.  I have been using them to add to my knowledge of VBA. 

I have been using the downloaded file accompanying this video as a basis of a project for myself (personal) as a stock system for my model collection.  Many of my controls are combo boxes from standard lists.  The basic work very well, but I hit on the idea of adding an extra page containing duplicate combo boxes and using these as a basis to set filters.  This works OK and a simple subroutine filters the data in the main worksheet.  However your "NavigateToRecord" ignores the filters and displays all the hidden rows.

I have started building a single element array to hold the row numbers of the visible rows which works OK, and I am about to write a different sub to replace your navigation routine.  However I wondered of there was a slick way your routine could be made to ignore the hidden rows?  If so this could save a lot of work.

As this video is now 2 years old, not sure if you will pick this up but thanks in anticipation.

Regards,

Colin Murdoch.

01 Oct 18 at 10:37

Hi Colin,

If I had to do this I'd probably use a collection to hold the visible ID cells and populate this when the form is loaded.  At the top of the form's code page you could add this:

'NEW LINE
Private VisibleIDCells As Collection

'NEW SUBROUTINE
Private Sub PopulateVisibleIDCells()
    
    Set VisibleIDCells = New Collection
    Dim r As Range
    
    For Each r In wsFilms.Range("A3", _
        wsFilms.Range("A1048576").End(xlUp)).SpecialCells(xlCellTypeVisible)
        
        VisibleIDCells.Add r, r.Address

    Next r
    
End Sub

You can then make a call to the PopulateVisibleIDCells subroutine in the Initialise event of the form.

You'll also need to modify the way the RecordCount property works:

Private Property Get RecordCount() As Long
    
    'ALTERED LINE
    RecordCount = wsFilms.Range("A3", _
        wsFilms.Range("A1048576").End(xlUp)).SpecialCells(xlCellTypeVisible).Cells.Count
    
End Property

At the beginning of the ReadDetails subroutine, you'll need to change the way you set a reference to the current ID cell:

Private Sub ReadFilmDetails()
    
    'ALTERED LINE
    Set CurrentIdCell = VisibleIDCells(CurrentRecordId)

I haven't tested this rigorously (it took long enough to remind myself what I'd done in the first place!) but the basics appear to work when I apply different filters to the list of films.

I hope that points you in the right direction!