Dim textBoxes As New Collection ' Holds the form's text boxes
Dim totalFields As Integer ' The total number of fields
Dim textboxNames() As String ' Holds the names of the text boxes
Dim editname As String, dbrow As Integer, c As String
Dim ctrl As Control, Lstfld As Integer
Dim Prog As String, key As String
On Error GoTo Errorhandler
' Set up the custom textBoxes collection
'
For Each ctrl In Me.Controls
If Left(ctrl.Name, 3) = "txt" Then
textBoxes.Add Item:=ctrl, key:=ctrl.Name
End If
Next 'ctrl
' Get the total number of fields in the list
' and then redimension the array of text box names
'
totalFields = Range("Database").Columns.Count
ReDim textboxNames(totalFields)
'
' Initialize the array of text box names in the
' order they appear in the list.
'
textboxNames(0) = "txtNhood"
textboxNames(1) = "txtPhase"
textboxNames(2) = "txtLot"
textboxNames(3) = "txtBlock"
editname = txtNhood & txtPhase & txtLot & txtBlock
If editname = "" Then
Unload Me
progend
End If
Select Case cmdAction.Caption
Case "OK"
Prog = "EditLot"
Range("aw1").Select
Cells.Find(What:=editname, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False).Activate
dbrow = ActiveCell.Row
Unload Me
Case "Delete"
editname = txtNhood & txtPhase & txtLot & txtBlock
Prog = "DeleteLot"
Range("aw1").Select
Cells.Find(What:=editname, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False).Activate
dbrow = ActiveCell.Row
Unload Me
Case "Display"
editname = txtNhood & txtPhase & txtLot & txtBlock
Prog = "Showlot"
Range("aw1").Select
Cells.Find(What:=editname, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False).Activate
dbrow = ActiveCell.Row
Unload Me
End Select
Errorhandler:
erchg editname, Prog
Unload Me
End Sub
Private Sub cmdCancel_Click()
Unload Me
progend
End Sub
Private Sub UserForm_Terminate()
Set textBoxes = Nothing
progend
End Sub
Sub erchg(editname, Prog)
MsgBox editname & " is not a valid lot ID. Please try again."
Unload Me
Application.Run (Prog)
End Sub