+ Reply to Thread
Results 1 to 7 of 7

Interactive User Form Data retreval

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-16-2016
    Location
    england
    MS-Off Ver
    11
    Posts
    115

    Interactive User Form Data retreval

    Hello,

    I'm trying to learn more VBA and have a problem, proberbly easy but here we go....

    I have a interactive user form and when i reun it i can only search for Numbers (see atatched)

    I have tried changing the code from IsNumeric to IsText but doesnt work, what am I missing here?

    Also for some reason if i enter more than 6 charecters it gives me a error.

    Thanks for looking if you do.

    D
    Attached Files Attached Files

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Interactive User Form Data retreval

    Slightly different approach here. Rather than looping through until you find a match, this just uses FIND to locate the row and recalls the data if found.

    Sub GetData()
        Dim RecallRow As Long
        Dim rng As Range
            
        With ThisWorkbook.Sheets("Sheet1")
            On Error Resume Next
            Set rng = .Range("A:A").Find(UserForm1.TextBox1, LookIn:=xlValues, LookAt:=xlWhole)
            On Error GoTo 0
            If Not rng Is Nothing Then
                RecallRow = rng.Row
                UserForm1.TextBox4 = Format(.Cells(RecallRow, "D").Value, "dd/mm/yyyy")
                UserForm1.TextBox2 = .Cells(RecallRow, "B")
                UserForm1.TextBox3 = .Cells(RecallRow, "C")
            End If
        End With
    End Sub
    Any use?

    BSB

  3. #3
    Forum Contributor
    Join Date
    02-16-2016
    Location
    england
    MS-Off Ver
    11
    Posts
    115

    Re: Interactive User Form Data retreval

    I copied the code in and it works great, can't say i totally understand it but it works......

    thankyou

  4. #4
    Forum Contributor
    Join Date
    02-16-2016
    Location
    england
    MS-Off Ver
    11
    Posts
    115

    Re: Interactive User Form Data retreval

    Hi just had a run through and now i get an error when i press the Edit/Add Button.

    D

  5. #5
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Interactive User Form Data retreval

    Quote Originally Posted by deanblew View Post
    Hi just had a run through and now i get an error when i press the Edit/Add Button.
    Sorry, I didn't look at that bit of code to test for errs.

    I have to go out for a while now but will come back to it when I return if nobody else has stepped in.

    BSB

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Interactive User Form Data retreval

    Added some comments in green to explain what it's all doing.

    Sub GetData()
        Dim RecallRow As Long
        Dim rng As Range
            
        With ThisWorkbook.Sheets("Sheet1") 'START WITH BLOCK MEANING THE EVERY ACTION BETWEEN HERE AND THE END WITH IS PERFORMED ON SHEET1 UNLESS STATED OTHERWISE
            On Error Resume Next 'STOPS THE NEXT LINE THROWING UP AN ERROR WHEN THE VALUE TYPED IS NOT FOUND
            Set rng = .Range("A:A").Find(UserForm1.TextBox1, LookIn:=xlValues, LookAt:=xlWhole) 'SETS THE rng VARIABLE BY LOOKING FOR THE VALUE IN TextBox1 IN COLUMN A ON SHEET 1.  IF FOUND THEN rng = THE CELL REFERENCE IT WAS FOUND IN.
            On Error GoTo 0 'RESETS THE ERROR NUMBER TO 0.  YOU CAN RESEARCH THIS FOR MORE DETAIL
            If Not rng Is Nothing Then 'IF THE A&A NUMBER WAS FOUND THEN DO THE NEXT BIT, IF NOT THEN DON'T
                RecallRow = rng.Row 'SETS THE ROW TO RECALL FROM TO THE ROW THE A&A NUMBER WAS FOUND IN
                UserForm1.TextBox4 = Format(.Cells(RecallRow, "D").Value, "dd/mm/yyyy") 'RECALLS THE DATE
                UserForm1.TextBox2 = .Cells(RecallRow, "B") 'RECALLS THE NAME
                UserForm1.TextBox3 = .Cells(RecallRow, "C") 'RECALLS THE CITY
            End If
        End With
    End Sub
    BSB

  7. #7
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Interactive User Form Data retreval

    Add the below to the beginning of the EditAdd sub:
    Dim id As String
    BSB

+ 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. Interactive user-form
    By Un-Do Re-Do in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-21-2017, 06:01 AM
  2. [SOLVED] Interactive User Form
    By AmirSoft in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-26-2014, 07:57 AM
  3. User form to post data and charts according to user defined selections
    By siroco79 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-12-2013, 11:16 AM
  4. Replies: 1
    Last Post: 08-28-2013, 05:04 PM
  5. [SOLVED] User forms - choosing location of your data to be shown in your user form
    By jasonbwt in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-29-2012, 08:48 AM
  6. Transfer User form data to a worksheet w.r.t. combobox item on the form
    By nm766 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-07-2011, 12:43 PM
  7. I'm trying to figure out what would work best for data entry and retreval.
    By Marc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-02-2006, 01:35 PM

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