473,467 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Coding search button (was Access and VBA Question)

48 New Member
Hi there

I have wrote a little script, that is used to search specific values that the User tips in.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdSearch_Click()
  3.  
  4.     Dim LSQL  As String
  5.     Dim LSearchString As String
  6.  
  7.     If Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
  8.         MsgBox "You must enter a search string."
  9.  
  10.     Else
  11.  
  12.         LSearchString = txtSearchString
  13.  
  14.         'Filter results based on search string
  15.         LSQL = "select Contacts.* , Work.* from Contacts, Work"
  16.         LSQL = LSQL & "where ((Contacts.ContactsID = Work.ContactsID) AND (FirstName LIKE '*" & LSearchString & "*'))"
  17.  
  18.         Form_SearchForm_sub.RecordSource = LSQL
  19.  
  20.         lblTitle.Caption = "Customer Details:  Filtered by '" & LSearchString & "'"
  21.  
  22.         'Clear search string
  23.         txtSearchString = ""
  24.  
  25.         MsgBox "Results have been filtered.  All Company Names containing " & LSearchString & "."
  26.  
  27.     End If 
  28.  
Now I always receive "Syntax Error: FROM" when I try to use it with the command button.

Does anyone see the mistake? Also, if somebody knows how to add more "search values", such as LastName etc. I would be very happy about it. I though it should be possible just to add
Expand|Select|Wrap|Line Numbers
  1.  
  2. OR LastName LIKE '*" & LSearchString & "* OR CostCenter LIKE '*" & LSearchString & "*  
  3.  
Thanks a lot
Aug 8 '07 #1
8 2493
Stang02GT
1,208 Recognized Expert Top Contributor
Hello Alive,

Just trying to get a better understanding of what you want to do here. You are trying to have a search field in a text box that is executed by a command button?
Aug 8 '07 #2
alive84
48 New Member
Hello Alive,

Just trying to get a better understanding of what you want to do here. You are trying to have a search field in a text box that is executed by a command button?
Hello Stang02GT,

I am actually trying to develop a DB-"google"-Form. So, a User tips for example a firstname, and in a subform it will show all relevant data to that user. In my my script it has to get the information from table Contacts and Work.

Thanks
Aug 8 '07 #3
Stang02GT
1,208 Recognized Expert Top Contributor
Alright thank you, that gives me a better understanding of what you are trying to do.
Aug 8 '07 #4
MikeTheBike
639 Recognized Expert Contributor
Hi there

I have wrote a little script, that is used to search specific values that the User tips in.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdSearch_Click()
  3.  
  4.     Dim LSQL  As String
  5.     Dim LSearchString As String
  6.  
  7.     If Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
  8.         MsgBox "You must enter a search string."
  9.  
  10.     Else
  11.  
  12.         LSearchString = txtSearchString
  13.  
  14.         'Filter results based on search string
  15.         LSQL = "select Contacts.* , Work.* from Contacts, Work"
  16.         LSQL = LSQL & "where ((Contacts.ContactsID = Work.ContactsID) AND (FirstName LIKE '*" & LSearchString & "*'))"
  17.  
  18.         Form_SearchForm_sub.RecordSource = LSQL
  19.  
  20.         lblTitle.Caption = "Customer Details:  Filtered by '" & LSearchString & "'"
  21.  
  22.         'Clear search string
  23.         txtSearchString = ""
  24.  
  25.         MsgBox "Results have been filtered.  All Company Names containing " & LSearchString & "."
  26.  
  27.     End If 
  28.  
Now I always receive "Syntax Error: FROM" when I try to use it with the command button.

Does anyone see the mistake? Also, if somebody knows how to add more "search values", such as LastName etc. I would be very happy about it. I though it should be possible just to add
Expand|Select|Wrap|Line Numbers
  1.  
  2. OR LastName LIKE '*" & LSearchString & "* OR CostCenter LIKE '*" & LSearchString & "*  
  3.  
Thanks a lot


You missed a SPACE between Work and where in the from clause, should be
LSQL = "select Contacts.* , Work.* from Contacts, Work "

although its more usual to us Contacts INNER JOIN Work ON etc.

I also think

OR LastName LIKE '*" & LSearchString & "* OR CostCenter LIKE '*" & LSearchString & "*

should work!

MTB
Aug 8 '07 #5
JKing
1,206 Recognized Expert Top Contributor
Good eye MTB!

The following string was missing closing single quotes. If it was a direct copy from your code and not just a string you typed on the fly for posting purposes, that would most likely be the source of your problem. Have a look I added them in below.

Expand|Select|Wrap|Line Numbers
  1. OR LastName LIKE '*" & LSearchString & "*' OR CostCenter LIKE '*" & LSearchString & "*'"
  2.  
Aug 8 '07 #6
alive84
48 New Member
You missed a SPACE between Work and where in the from clause, should be
LSQL = "select Contacts.* , Work.* from Contacts, Work "

although its more usual to us Contacts INNER JOIN Work ON etc.

I also think

OR LastName LIKE '*" & LSearchString & "* OR CostCenter LIKE '*" & LSearchString & "*

should work!

MTB
Thanks MTB that was the problem! Thanks for finding such a minuscule mistake. Thanks

Unfortunately, I am having another problem now. When I open the search form two Parameter Value Boxes appear. It asks me for the ContactsID and WorkID. How can I avoid that.

thanks
Aug 8 '07 #7
alive84
48 New Member
Thanks MTB that was the problem! Thanks for finding such a minuscule mistake. Thanks

Unfortunately, I am having another problem now. When I open the search form two Parameter Value Boxes appear. It asks me for the ContactsID and WorkID. How can I avoid that.

thanks

The problem disappeared...:-) ... I do not know what I did, that it vanished.

Thanks to all for the help
Aug 9 '07 #8
missinglinq
3,532 Recognized Expert Specialist
Please remember to provide a meaningful Title for any threads you start! This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions. It is difficult for the experts to answer questions when there is not enough details provided to understand the problem.

Please take the time to read the Posting Guidelines, paying particular attention to Give a clear title to your question.

http://www.thescripts.com/forum/thread559246.html


Thank you and Welcome to TheScripts!!

Linq ;0)>
Aug 9 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Greg | last post by:
I have a page that searches a database by a repairman's name and by a date range. It pulls info by the repairman's name but pulls all info in the database regardless of the date. Below is the code...
1
by: Spartanicus | last post by:
I'm pondering what the various drawbacks are of the methods to code UI elements who's function relies on javascript and css. Currently on http://www.pan-europe.utvinternet.ie/ I use styled <a>...
3
by: Colleyville Alan | last post by:
I have a incremental search box that has been working fine for a couple of months but is now acting up. This search box is from the cd that comes with Getz's book, so I did not write it and have...
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
1
by: higgy2005 | last post by:
Hi there, I would be very greatful if somebody could help me with my trouble using VBA to code a button on a form. Basically what i want to happen is on the click of the button i want it to...
4
by: saima khushbakht | last post by:
hi i need coding for find button using adodc control.the search should be by name.if we enter the name of employee then search button should search name from data base either it exists in batabase...
2
by: Mark | last post by:
Hi All, I am creating a music database for a friend and have run into a problem. Within the ALBUM table, I wanted to store the ARTIST_ID rather than the ARTIST_NAME. To do this, I intended to have...
8
by: =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post by:
I am working with Visual C# window and in my application I need to use a button ( NEXT) . The button should displays one panel with its objects each time it clicked. I already developed the codes...
0
by: Ignacio Machin ( .NET/ C# MVP ) | last post by:
On Apr 22, 2:51 pm, Tammy Nejadian <TammyNejad...@discussions.microsoft.comwrote: Do a search in the archives of this NG, look for "wizard" you will find a lot of examples
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.