Consulting

Results 1 to 2 of 2

Thread: Sleeper: Simple database userforms

  1. #1

    Sleeper: Simple database userforms

    I am relatively new to this site and to doing VBA in general, so forgive my stone-age quality code. With that in mind, I have been able to create a simple insurance wizard to track certificates and I am using a simple userform for data entry. I was successful at the data entry using userforms but I am stumped on how to pull the records back in to the userform to view/modify them as needed. If anyone could help me with a simple solution to accomplish this I would appreciate it. I have included a copy of my excel file as a reference.

    (these seem to fit my state of mind on this one!)

    Thank you in advance for any suggestions.

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Hi and welcome to VBAX
    What you're doing here, it appears to me, is effectively creating a data base with each record occupying one row on the Certificates worksheet. I'm assuming you want to search the records for something with the search form and if successful, display that record on the newdataform for modification... correct?
    Assuming you can get hold of whichever record it is you want, populating the form could work like this:
    Let's say you got 10 fields... thats 10 text boxes and ten cells on the worksheet. You could use the "Tag" property of each text box to enter the corresponding column number on the worksheet and use something like this to fill all the fields in one loop

    For Each ctrl In newdataform.Controls
        If ctrl.Tag <> "" Then
            ctrl.Text = Sheets("Certificates").Cells(targetrow, CInt(ctrl.Tag)).Value
        End If
    Next
    Note that empty Tag values are not processed so none of the other controls should have theirs used. Also, the Tag property is a string so to use it as a column index in "Cells" I've cast it as an integer, CInt()
    Well thats a start... looks like you've got a fair bit of work there!
    One word of advice, you should use "Option Explicit" at the start of each module/form to force you to declare all your variables from the start. (make it automatic in the VBEditor|Tools|Options Edit tab check "Require variable declaration"). There's a few good reasons to do this, not least it will make it easier for you as the code gets more complicated.
    Good luck
    K :-)

Posting Permissions

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