Recall from data/spreadsheet to userform for edit

sureshtrb

Board Regular
Joined
Mar 24, 2013
Messages
105
I have made a form to enter the details to save in database. I want to recall the data for editing. Using web help, used the below code, but showing error when i press the findnext or findprevious command and highlighting in
Code:
    Set LastFind = Where.Find(Me.NO, LookIn:=xlValues, LookAt:=xlPart)
my code for recall is
Code:
Private Sub UserForm_Initialize()


Dim Where As Range
'End Sub
NO.TAG = "A"
  SCOPETEST.TAG = "B"
  LOCATION.TAG = "C"
  RECDDATE.TAG = "D"
  INSPYES.TAG = "E"
' .......(around 170 lines)
Private Sub ClearForm()  'Clears every control that has a Tag property
  Dim C As Control
  For Each C In Me.Controls
    If C.TAG <> "" Then C.Value = ""
  Next
End Sub


Private Sub FillForm()
  'Fills every control that has a Tag property
  Dim C As Control
  For Each C In Me.Controls
    If C.TAG <> "" Then
      'Fill the textbox from the column specified by the Tag property
      C.Value = Intersect(LastFind.EntireRow, LastFind.Parent.Columns(C.TAG))
    End If
  Next
End Sub


Private Sub cbFindNext_Click()
Dim LastFind As Range
Dim Where As Range
  'Commandbutton "FindNext"
  If LastFind Is Nothing Then
    Set LastFind = Where.Find(Me.NO, LookIn:=xlValues, LookAt:=xlPart)
  Else
    Set LastFind = Where.FindNext(LastFind)
  End If
  If LastFind Is Nothing Then ClearForm Else FillForm
End Sub


Private Sub cbFindPrev_Click()
Dim Where As Range
Dim LastFind As Range
  'Commandbutton "FindPrevious"
  If LastFind Is Nothing Then
    Set LastFind = Where.Find(Me.NO, LookIn:=xlValues, LookAt:=xlPart)
  Else
    Set LastFind = Where.FindPrevious(LastFind)
  End If
  If LastFind Is Nothing Then ClearForm Else FillForm
End Sub


Private Sub NO_Change()
Dim Where As Range
Dim LastFind As Range
  'Initialize the search if the name becomes different
  If Not LastFind Is Nothing Then
    If NO <> LastFind Then Set LastFind = Nothing
  End If
End Sub
In the beginning of the code I have already inserted
Code:
Option Explicit
Help me and suggest, where the mistake I am doing.
 

Forum statistics

Threads
1,081,415
Messages
5,358,533
Members
400,502
Latest member
price83

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top