If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Use InStr to Strip * Entered by User

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-21-11, 10:46
db_questions db_questions is offline
Registered User
 
Join Date: Dec 2010
Posts: 22
Question Use InStr to Strip * Entered by User

Good Morning,

I'm using an Access form to collect input from a user and then export search results to Excel. The problem is I allow a user to select from a drop box or use a wildcard to see more results. All is fine if no wildcard is used and I use only the "Else" condition below. Each statement below works separately so I believe the problem is with my If Then and / or the way I'm trying to strip the user entered * by replacing with a space.

All help is greatly appreciated.

Dim xSrch As String
Dim isWildcard As String

isWildcard = InStr("'*" & Me.txtFindResult & "*'", "*")
sSearch = Replace(Me.txtFindResult, "*", "")

If isWildcard > 0 Then
‘Wildcard
xSQL = "SELECT B.[Book] FROM tblBooks AS B " _
& "WHERE B.Books Like '%" & Me.txtFindResult & "%' ;"

Else
‘No Wildcard
xSQL = "SELECT B.[Book] FROM tblBooks AS B " _
& "WHERE B.Books Like '" & Me.txtFindResult & "' ;”

Thanks!
Reply With Quote
  #2 (permalink)  
Old 06-21-11, 11:25
db_questions db_questions is offline
Registered User
 
Join Date: Dec 2010
Posts: 22
Problem solved. The wildcard section should use xSrch, not the original txtFindResult. Should have looked closer before I posted.
Reply With Quote
Reply

Tags
instr, replace, vba, wildcard

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On