Select Case selecting wrong boolean for option buttons in userform

Curben

Board Regular
Joined
Aug 18, 2011
Messages
65
My userform is performing backwards if the option button for whole is set to true it searches for partial, if its set for part it searchs whole. Steping through the case select does not seem to be recognizing true and false correctly.
I did verify that i didnt name them backwards. optWhole is set to true by default. I am not sure what is missing

Code:
Option Explicit
Dim SrchCrit As String
Dim SrchFld As String
Dim SrchRow As Integer
Dim SrchOpt As Boolean
Dim SrchType As String


Private Sub btnNextRec_Click()
    Selection.FindNext(After:=ActiveCell).Activate
    Call RetrieveRec
End Sub



Private Sub btnPrevRec_Click()
    Selection.FindPrevious(After:=ActiveCell).Activate
    Call RetrieveRec
End Sub



Private Sub btnSearch_Click()

SrchCrit = txtCriteria.Value
SrchRow = Application.VLookup(cmbField, Range("tbl_FldLU"), 2, False)
Select Case SrchOpt
    Case optWhole = True
        SrchType = xlWhole
    Case optPartial = True
        SrchType = xlPart
End Select
Range("A2").Offset(0, SrchRow).Resize(400, 1).Select

Selection.Find(What:=SrchCrit, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=SrchType, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate
Call RetrieveRec

End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Unless you are setting srchOpt somewhere, it is False and hence your select case evaluates the opposite condition.
 
Upvote 0
changed to an if statement and it works, not sure what i was thinking at the time

Code:
If optWhole = True Then
    SrchType = xlWhole
Else
    SrchType = xlPart
End If
 
Upvote 0

Forum statistics

Threads
1,216,068
Messages
6,128,595
Members
449,460
Latest member
jgharbawi

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