Consulting

Results 1 to 4 of 4

Thread: Auto fill a form

  1. #1

    Auto fill a form

    Hi All, I am trying to write a macro that will auotfill some fields on a form sheet (as in a worksheet made to look like a form not an actual form) from a second data source sheet. The data will be a large and unfriendly database dump. Users will want to plug in an ID number on their form, click a cmd button and see the generic Project Details fields auto fill based on a comparison of the ID the user entered and the ID column in the source sheet. I have attached an early test version. I have made some headway with the code but its crap, doesnt work and would almost certainly confuse matters so I haven't posted it. Will do when/if i get it anything like working. Thanks for any help in advance.

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I don't see an ID number on the source sheet. how is the connection made?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub CommandButton1_Click()
    Dim iMatch As Long

    With Me

    If .Range("D4").Value <> "" Then

    On Error Resume Next
    iMatch = Application.Match(.Range("D4").Value, Worksheets("Source").Columns(1), 0)
    On Error GoTo 0
    If iMatch > 0 Then

    .Range("D8").Value = Worksheets("Source").Cells(iMatch, "C").Value
    .Range("D9").Value = Worksheets("Source").Cells(iMatch, "D").Value
    .Range("D10").Value = Worksheets("Source").Cells(iMatch, "E").Value
    .Range("D11").Value = Worksheets("Source").Cells(iMatch, "F").Value
    .Range("D12").Value = Worksheets("Source").Cells(iMatch, "G").Value
    End If
    End If
    End With
    End Sub
    [/vba]

    You would do well do add a Data Validation drop-down to D4 with the values for the ids.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Thanks very much, perfect!

Posting Permissions

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