Search Function (1 Viewer)

Coolzie1

Registered User.
Local time
Today, 05:55
Joined
May 13, 2017
Messages
11
Hi all,

As you may have seen in a previous post of mine I am quite new to access and VBA. I am setting up a search database which will be being used by the team I work for at work and need to search through all of the postcodes in the UK as part of our job role to see what delivery Windows are offered for each one.

I currently have it basically set up to search and find the result however when you type in "D" for example it will bring up "BD1 1,BD1 2, etc" rather than "DA1 1, DA1 2, etc" and I know this is due to it bringing up the first result in the list as it works its way down however I need it to look through and if "D" is the first character provided it will bring back all the results with D as the first letter back so it's saving time scrolling through all the results with the specified search criteria in it.

Current code looks something like:

Dim search as string
Dim task as string
If ISNULL (me.txtSearch) OR txtSearch = "" then
MsgBox "No Results Found" vbYESOnly
ELSE
Search = txtSearch.Value
Task = "SELECT FROM * PostcodeT WHERE (postcode LIKE ""*" & Search & "*"")
Me.RecordSource = Task
End If

Thanks in advance for any help given :)
 

Cronk

Registered User.
Local time
Today, 16:55
Joined
Jul 4, 2013
Messages
2,770
Understand how the wild 'card' works.

Like "*D*" will return anything-D-anything

If you only want strings starting with D then use
Like "D*"

That is, in your code drop off the first asterisk.
 

Coolzie1

Registered User.
Local time
Today, 05:55
Joined
May 13, 2017
Messages
11
Thank you so much, I never knew that was specifically what was being done with the asterisk as I've used a pre-set bit of code from online and adapted it to fit my form and table. I feel stupid for spending hours searching through websites and it could have been sorted in 5 seconds.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:55
Joined
Feb 28, 2001
Messages
27,001
Don't feel so bad. When you are new to something, your problem is not only not knowing what is wrong, but not knowing enough of the verbiage to be able to ask the right question because you don't know the right word to describe something.

For instance, any other time you open a visual "thing" in an application, you call it either a window or a page. But in Outlook, when you are using an application object from an Access application as the driving force, the body of your message becomes opened in an "Inspector" and you have to know that word to even know how to look it up properly. When I ran into that one, I would have torn my hair out - except Mother Nature got there first.
 

Users who are viewing this thread

Top Bottom