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
my code for recall is
In the beginning of the code I have already inserted
Help me and suggest, where the mistake I am doing.
Code:
Set LastFind = Where.Find(Me.NO, LookIn:=xlValues, LookAt:=xlPart)
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