Recall from data/spreadsheet to userform for edit

sureshtrb

Board Regular
Joined
Mar 24, 2013
Messages
106
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.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,214,798
Messages
6,121,630
Members
449,041
Latest member
Postman24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top