Require correct positioning of Boolean Value to overcome some hassles

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
688
Hello

I had to incorporate the REM marks below to see the Searched value of comboBox which displays the respective curRow Data in All Textboxes of Respective Columns of that curRow

coding in Class Module: Class2AllTextboxes
Code:
Option Explicit
Public WithEvents AllTextBoxEvent As MSForms.TextBox

Private Sub AllTextBoxEvent_Change()
Dim i As Integer
    If dontUpdate = True Then Exit Sub
[COLOR=#ff0000][B]           'For i = 1 To 6
           '    Ws.Cells(curRow, i).Value = UserForm1.Controls("textbox" & i).Value
           '  Next i
[/B][/COLOR]
End Sub
if REM marks are removed from above For Next loop then the result is : that all the text boxes become empty except for Textbox1 which displays the respective Searched value of curRow of Column 1 and i am able to modify the data in Textbox1 which is also displayed in Column1 of respective curRow

Really Dont know where to place exactly the boolean Value so that i can see the Respective Searched value of curRow in the Respective Textboxes with Respective Columns

The above ForLoop enables to update the record from Textboxes in respective columns

would Request anyone to try the coding at your end and in worksheet1 kindly fill the numeric data in column A from Row A2 and other 5 columns Alphanumeric data
Coding in Module1
Code:
 Option Explicit

Global curRow As Long
Global curRec As Integer
Global Const StartRow As Long = 2
Public row As Long


Public Ws As Worksheet
Public dontUpdate As Boolean
Coding in userform1
Code:
Option Explicit
Public AllTextBoxEventes As New Collection
Public Lastrow As Long
Private IsArrow As Boolean
Dim SearchRange As Range
Dim FindRow As Range


Private Sub cmbSearch_Change()

Dim i As Long
    With Me.cmbSearch
        If Not IsArrow Then .List = Worksheets("Sheet1").Range("A2").CurrentRegion.Offset(1, 0).Value
        
        If .ListIndex = -1 And Val(Len(.Text)) Then
            For i = .ListCount - 1 To 0 Step -1
                If InStr(1, .List(i), Val(.Text), 1) = 0 Then .RemoveItem i
            Next i
            .DropDown
        End If
        
        If UserForm1.cmbSearch.ListCount = 0 Then
           MsgBox "You dont have that no."
           GetRecordEmpty curRow
           Exit Sub
          End If
            
          If UserForm1.cmbSearch.Text = "" Then
              GetRecordEmpty curRow
         Else
            Set SearchRange = Ws.Range(Cells(2, "A"), Cells(Rows.Count, "A").End(xlUp))
            Set FindRow = SearchRange.Find(UserForm1.cmbSearch.Text, LookIn:=xlValues, lookat:=xlWhole)


           On Local Error GoTo errSub
            curRow = FindRow.row
            
            Rows(curRow).Select
            GetRecord curRow 
            curRec = FindRow.row - 1
            UserForm1.lblSrNo.Caption = Format$(curRec)
        End If
    End With

errSub:
Exit Sub

End Sub

Private Sub cmbSearch_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    IsArrow = KeyCode = vbKeyUp Or KeyCode = vbKeyDown
    If KeyCode = vbKeyReturn Then Me.cmbSearch.List = Worksheets("Sheet1").Range("A2").CurrentRegion.Offset(1, 0).Value
End Sub

Private Sub cmbSearch_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
     KeyAscii = -KeyAscii * CLng(Chr(KeyAscii) Like "#")
     If KeyAscii = 0 Then Beep
End Sub

Private Sub UserForm_Initialize()

Set Ws = Worksheets("Sheet1")
Ws.Activate


cmbSearch.List = Worksheets("Sheet1").Range("A2").CurrentRegion.Offset(1, 0).Value


Dim oneTextBox As Variant
Dim allTxtBxes As Class2AllTextboxes
Set AllTextBoxEventes = New Collection


Dim i As Integer
 For i = 1 To 6
            Set allTxtBxes = New Class2AllTextboxes
            Set allTxtBxes.AllTextBoxEvent = UserForm1.Controls("Textbox" & Format(i))
            AllTextBoxEventes.Add Item:=allTxtBxes
Next i
Set allTxtBxes = Nothing


curRec = 1
UserForm1.lblSrNo.Caption = Format$(curRec)

End Sub

Sub GetRecord(ByVal row As Long)
Dim Ws As Worksheet
Set Ws = Worksheets("Sheet1")
    UserForm1.Tag = xlOff
    If row < StartRow Then row = StartRow
    Rows(row).Select
    UserForm1.Tag = xlOn

Dim i As Integer
For i = 1 To 6
   UserForm1.Controls("TextBox" & i).Value = Ws.Cells(row, i).Value
Next i
End Sub

Sub GetRecordEmpty(ByVal row As Long)
Dim Ws As Worksheet
Set Ws = Worksheets("Sheet1")
    UserForm1.Tag = xlOff
    If row < StartRow Then row = StartRow
    Rows(row).Select
    UserForm1.Tag = xlOn


Dim i As Integer
For i = 1 To 6
   UserForm1.Controls("TextBox" & i).Value = ""
Next i
        curRec = 1
        UserForm1.lblSrNo.Caption = Format$(curRec)
End Sub


Thanks NimishK
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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