Search Code Query (1 Viewer)

Paul Ager

New member
Local time
Today, 09:14
Joined
Sep 7, 2009
Messages
8
Hi Guys,

I'm new to all this so please bare with me if I miss anything or dont explain something clearly enough. I have a query with the code below.
Although the code works prefectly I'd like the search to include a wild card option i.e. add * before the reference query in the text box.
Does anybody have any ideas? Any help would be greatly appreciated.

RefID is the field being searched.
txtRefSeach is the text box the data is input.
cmdRefSearch is the button.

Private Sub cmdReqSearch_Click()

Dim strRefRef As String
Dim strRefSearch As String


'Check txtRefSearch for Null value or Nill Entry first.

If IsNull(Me![txtRefSearch]) Or (Me![txtRefSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtRefSearch].SetFocus

Exit Sub
End If

'Performs the search using value entered into txtRefSearch
'and evaluates this against values in RMRefID


DoCmd.ShowAllRecords
DoCmd.GoToControl "RefID"
DoCmd.FindRecord Me!txtRefSearch


RefID.SetFocus
strRefRef = RefID.Text
txtRefSearch.SetFocus
strRefSearch = txtRefSearch.Text


'If matching record found sets focus in RMRefID and shows msgbox
'and clears search control

If strRefRef = strRefSearch Then
MsgBox "Reference Found For: " & strRefSearch, , "Success!"
RefID.SetFocus
txtRefSearch = ""


'If value not found sets focus back to txtRefSearch and shows msgbox

Else
MsgBox "Reference Not Found For: " & strRefSearch & " Please Try Again", _
, "Invalid Search Reference!"
txtRefSearch.SetFocus

End If

End Sub
 

kjohnson

Registered User.
Local time
Today, 01:14
Joined
Oct 8, 2008
Messages
31
You should be able to create a variable that concatenates a string containing the * and the text box input

Code:
Dim Input As String

Input = * & [[SIZE=2]txtRefSeach]
[/SIZE]

 

MSAccessRookie

AWF VIP
Local time
Today, 04:14
Joined
May 2, 2008
Messages
3,428
You should be able to create a variable that concatenates a string containing the * and the text box input

Code:
Dim Input As String
 
Input = * & [[SIZE=2]txtRefSeach][/SIZE]

While the concept of this advice seems to be good, I believe that the word INPUT is still reserved in Visual Basic. Choosing a different (and perhaps more descriptive) name might be a safer approach.
 

kjohnson

Registered User.
Local time
Today, 01:14
Joined
Oct 8, 2008
Messages
31
I believe that the word INPUT is still reserved in Visual Basic.

It probably is, but I used it just as a generic "this is the input" variable.

But thank you for pointing that out. I should have mentioned that.
 

MSAccessRookie

AWF VIP
Local time
Today, 04:14
Joined
May 2, 2008
Messages
3,428
It probably is, but I used it just as a generic "this is the input" variable.

But thank you for pointing that out. I should have mentioned that.

I was not intending to be critical. Instead I was really trying to save the OP from potential future frustrations in the event that I was right.
 

kjohnson

Registered User.
Local time
Today, 01:14
Joined
Oct 8, 2008
Messages
31
I understand, I didn't take it as being critical.
And you have helped me out with many a problem.
And I appreciate your help very much :)
 

Paul Ager

New member
Local time
Today, 09:14
Joined
Sep 7, 2009
Messages
8
Thanks guys I'll give it a go and let you know the outcome.
 

Users who are viewing this thread

Top Bottom