473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Search Form

67
Hi all

My access and vb knowledge is limited.What i am wondering is - Is it possible to have a textbox you can enter data into, click a button to start the search that searches a combobox that is linked to a table via a query?

I would be grateful for any help and examples
Nov 5 '08 #1
8 1241
PianoMan64
374 Expert 256MB
Hi all

My access and vb knowledge is limited.What i am wondering is - Is it possible to have a textbox you can enter data into, click a button to start the search that searches a combobox that is linked to a table via a query?

I would be grateful for any help and examples
Hey Wayneyh, Welcome to Byte:

To answer your question in general, yes it can be done.

But normall the way that I've been doing it successfully is to put a List control on the form that isn't bound to any data source at all, and in VB code I create the string value that becomes that data soruce by which fields on the form that I fill in set the values that I'm looking for and when I click the search button, it builds the search string that is passed as the Rowsource value for the list control. Then when I refresh the list control using me.listcontrolname.requery, and the me.repaint, I then get a list of the items that I am looking for. I hope that makes sense.

If you need code examples, please let me know, I'm more than happy to provide them.

Hope that helps,

Joe P.
Nov 10 '08 #2
missinglinq
3,532 Expert 2GB
Actually, you can use a combobox for this and it doesn't require writing any code at all!

If you haven't already done so, create a form based on your table or query, including all the fields you want displayed. Then simply:

Add a combo box to your form. The Combobox Wizard will pop up

Select "Find a record based on the value I selected in my combobox."

From the table or query the form is based on, click on the field you're searching by (a field that is unique for each record) to move it to the right side.

Hit Next.

Size the column appropriately.

Hit Next.

Name the combobox.

Hit Finish.

Now you can drop the combobox down and scroll down to the item to search by, or you can start to enter the item, and the combobox will "autofill" as you type. Hit <Enter> and the record will be retrieved.

Welome to Bytes!

Linq ;0)>
Nov 10 '08 #3
Wayneyh
67
Thanks PianoMan64

I think what you are saying would work for me and if you have an example it would be most appreciated as i have reached my limit with coding.

Regards
Nov 10 '08 #4
Wayneyh
67
Hi missinglinq

This wouldn't work as i don't want to search through the combo box. I want a text box to type the info i am wanting to look for, then click a search button that searches the combo box that is linked to a table through a query.

Regards
Nov 10 '08 #5
PianoMan64
374 Expert 256MB
Hi missinglinq

This wouldn't work as i don't want to search through the combo box. I want a text box to type the info i am wanting to look for, then click a search button that searches the combo box that is linked to a table through a query.

Regards
Here is a code example of how I build a SQL String with a tables that is either local or linked to the current MDB/MDE/ACCDB file:

Expand|Select|Wrap|Line Numbers
  1. Private Sub SeachBtn_Click()
  2.     Dim strSQL As String
  3.     Dim Criteria As String
  4.  
  5.     If IsNull(Me.sIDNo) And IsNull(Me.sSFG_ID) And _
  6.        IsNull(Me.sLastName) And IsNull(Me.sFirstName) And _
  7.        IsNull(Me.sPolicyNo) And IsNull(Me.sCompanyID) And _
  8.        IsNull(Me.sReceivedDate) And IsNull(Me.sSignDate) And _
  9.        IsNull(Me.sBatchNo) And Not Me.sShowMine Then
  10.  
  11.         strSQL = strSQL & "SELECT Doc_View.ID, Doc_View.SFG_ID as [SFG ID], " & vbCrLf & _
  12.                           "       Doc_View.LASTNAME as [Last Name], " & vbCrLf & _
  13.                           "       Doc_View.FIRSTNAME as [First Name], " & vbCrLf & _
  14.                           "       Doc_View.POLICYNO as [Policy No], " & vbCrLf & _
  15.                           "       Doc_View.DOCRECDATE as [Rec Date], " & vbCrLf & _
  16.                           "       Doc_View.DOCSIGNDATE as [Signed Date], " & vbCrLf & _
  17.                           "       Doc_View.RECDATE as [Received], " & vbCrLf & _
  18.                           "       Doc_View.BATCHNO as [Batch No], " & vbCrLf & _
  19.                           "       Doc_View.USERNAME as UserName, " & vbCrLf & _
  20.                           "       Doc_View.STATUS as Status " & vbCrLf & _
  21.                           "FROM Doc_View;"
  22.         Me.BenDes.RowSource = strSQL
  23.     Else
  24.  
  25.                strSQL = strSQL & "SELECT Doc_View.ID, Doc_View.SFG_ID as [SFG ID], " & vbCrLf & _
  26.                           "       Doc_View.LASTNAME as [Last Name], " & vbCrLf & _
  27.                           "       Doc_View.FIRSTNAME as [First Name], " & vbCrLf & _
  28.                           "       Doc_View.POLICYNO as [Policy No], " & vbCrLf & _
  29.                           "       Doc_View.DOCRECDATE as [Rec Date], " & vbCrLf & _
  30.                           "       Doc_View.DOCSIGNDATE as [Signed Date], " & vbCrLf & _
  31.                           "       Doc_View.RECDATE as [Received], " & vbCrLf & _
  32.                           "       Doc_View.BATCHNO as [Batch No], " & vbCrLf & _
  33.                           "       Doc_View.USERNAME as UserName, " & vbCrLf & _
  34.                           "       Doc_View.STATUS as Status " & vbCrLf & _
  35.                           "FROM Doc_View " & vbCrLf & _
  36.                           "WHERE (" & vbCrLf
  37.                 If Not IsNull(Me.sIDNo) Then
  38.                     If Len(Criteria) Then
  39.                         Criteria = Criteria & " AND ((Doc_View.ID)=" & Me.sIDNo & ") " & vbCrLf
  40.                     Else
  41.                         Criteria = Criteria & "((Doc_View.ID)=" & Me.sIDNo & ")" & vbCrLf
  42.                     End If
  43.                 End If
  44.                 If Not IsNull(Me.sSFG_ID) Then
  45.                     If Len(Criteria) > 0 Then
  46.                         Criteria = Criteria & " AND ((Doc_View.SFG_ID) = '" & Me.sSFG_ID & "')" & vbCrLf
  47.                     Else
  48.                         Criteria = Criteria & "((Doc_View.sfg_id) = '" & Me.sSFG_ID & "')" & vbCrLf
  49.                     End If
  50.                 End If
  51.                 If Not IsNull(Me.sLastName) Then
  52.                     If Len(Criteria) > 0 Then
  53.                         Criteria = Criteria & " AND ((Doc_View.LastName)='" & UCase(Me.sLastName) & "')" & vbCrLf
  54.                     Else
  55.                         Criteria = Criteria & "((Doc_view.LastName)='" & UCase(Me.sLastName) & "')" & vbCrLf
  56.                     End If
  57.                 End If
  58.                 If Not IsNull(Me.sFirstName) Then
  59.                     If Len(Criteria) > 0 Then
  60.                         Criteria = Criteria & " AND ((Doc_View.FirstName) = '" & UCase(Me.sFirstName) & "')" & vbCrLf
  61.                     Else
  62.                         Criteria = Criteria & "((Doc_view.FirstName)='" & UCase(Me.sFirstName) & "')" & vbCrLf
  63.                     End If
  64.                 End If
  65.                 If Not IsNull(Me.sPolicyNo) Then
  66.                     If Len(Criteria) > 0 Then
  67.                         Criteria = Criteria & " AND ((Doc_View.PolicyNo) = '" & Me.sPolicyNo & "')" & vbCrLf
  68.                     Else
  69.                         Criteria = Criteria & "((Doc_View.PolicyNo) = '" & Me.sPolicyNo & "')" & vbCrLf
  70.                     End If
  71.                 End If
  72.                 If Me.sCompanyID <> "SI" Then
  73.                     If Len(Criteria) > 0 Then
  74.                         Criteria = Criteria & " AND ((Doc_View.CompanyID) = '" & UCase(Me.sCompanyID) & "')" & vbCrLf
  75.                     Else
  76.                         Criteria = Criteria & "((Doc_View.CompanyID) = '" & UCase(Me.sCompanyID) & "')" & vbCrLf
  77.                     End If
  78.                 Else
  79.                     If Len(Criteria) > 0 Then
  80.                         Criteria = Criteria & " AND ((Doc_View.CompanyID) = 'SI')" & vbCrLf
  81.                     Else
  82.                         Criteria = Criteria & "((Doc_View.CompanyID) = 'SI')" & vbCrLf
  83.                     End If
  84.                 End If
  85.                 If Not IsNull(Me.sReceivedDate) Then
  86.                     If Len(Criteria) > 0 Then
  87.                         Criteria = Criteria & " AND ((Doc_View.DocRecDate) = #" & Me.sReceivedDate & "#)" & vbCrLf
  88.                     Else
  89.                         Criteria = Criteria & "((Doc_View.DocRecDate) = #" & Me.sReceivedDate & "#)" & vbCrLf
  90.                     End If
  91.                 End If
  92.                 If Not IsNull(Me.sSignDate) Then
  93.                     If Len(Criteria) > 0 Then
  94.                         Criteria = Criteria & " AND ((Doc_View.DocSignDate) = #" & Me.sSignDate & "#)" & vbCrLf
  95.                     Else
  96.                         Criteria = Criteria & "((Doc_View.DocSignDate) = #" & Me.sSignDate & "#)" & vbCrLf
  97.                     End If
  98.                 End If
  99.                 If Not IsNull(Me.sBatchNo) Then
  100.                     If Len(Criteria) > 0 Then
  101.                         Criteria = Criteria & " AND ((Doc_View.BatchNo) = " & Me.sBatchNo & ")" & vbCrLf
  102.                     Else
  103.                         Criteria = Criteria & "((Doc_View.BatchNo) = " & Me.sBatchNo & ")" & vbCrLf
  104.                     End If
  105.                 End If
  106.                 If Me.sShowMine Then
  107.                     If Len(Criteria) > 0 Then
  108.                         Criteria = Criteria & " AND ((Doc_View.UserName) = '" & CurrentUser() & "')" & vbCrLf
  109.                     Else
  110.                         Criteria = Criteria & "((Doc_View.UserName) = '" & CurrentUser() & "')" & vbCrLf
  111.                     End If
  112.                 End If
  113.  
  114.  
  115.                 strSQL = strSQL & Criteria & ") ORDER BY RecDate"
  116.  
  117.                 'MsgBox strSQL, vbOKOnly
  118.                 Me.BenDes.RowSource = strSQL
  119.     End If
  120.  
  121. End Sub
  122.  
Now what I've done is copy and pasted a working example of one of my projects.

What you have to keep in mind is that this assumes that you have a table that is named "Doc_View" and all the items that start with "me." are all controls that are on my current form. this includes the me.BenDes control which is a List Control.

As you can see, I build the SQL portion and the Criteria Portion separately, and then combined them together at the bottom and then that becomes the data source for the List Control box.

Just make sure that on the Listbox Control that you set the following field values ahead of time.

Column Count = <the number of columns of data that is returned by the query>
ColumnWidths =<The value in Picos separated by ; 1" = 1440 picos> example 720 = .5"
Column Heads=<Yes/No> If you want Column Fields names at the top of the list, set this to yes, otherwise set to NO.

Bound Column=1 I'm assuming that the Primary key value will be the first field in the list of records coming out. If you want to bind the value of the ListControl to another value, then change the number to the column that has the value in it that you seek. Keep in mind that this must be a Key value that will uniquely identify each record. That is why I say just leave it at one.

That should get you started.

Oh, one more thing, I'm assuming by the code that I've sent, that the name of the search button control is SearchBtn and that it is going to be connected to the On Click event.

Hope that helps,

If you have any other questions, please let me know.

THanks,

Joe P.
Nov 12 '08 #6
Wayneyh
67
Thanks Joe

I will have a mess about with your code and see if i can get it to work for me

Regards

Wayne
Nov 12 '08 #7
PianoMan64
374 Expert 256MB
Thanks Joe

I will have a mess about with your code and see if i can get it to work for me

Regards

Wayne
I await to hear how it works out.
Nov 12 '08 #8
Wayneyh
67
Hi Joe

I have created a Table and Form for the code you gave to me. I see the code has an sCompanyID, how do i put that into the form? I am also getting a runtime error as follows -

If IsNull(Me.sIDNO) And IsNull(Me.sSFG_ID) And _
IsNull(Me.sLASTNAME) And IsNull(Me.sFIRSTNAME) And _
IsNull(Me.sPOLICYNO) And IsNull(Me.sCompanyID) And _
IsNull(Me.sRECEIVEDDATE) And IsNull(Me.sSIGNDATE) And _
IsNull(Me.sBATCHNO) And Not Me.sSHOWMINE Then

All this part is highlighted in yellow. Please advise.

Regards

Wayne
Nov 12 '08 #9

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

Similar topics

1
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
2
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned...
1
by: bdawg | last post by:
what i want to do is create several radio buttons and a textbox for searching purposes. the search will perform a search depending on which button the user selects. here is what i have now: ...
1
by: N. Graves | last post by:
Hi, I want to have a Search Dialog box that has several text box and fields to build a search and display the results in a form. I can do everything that I need to if I us a report but I would...
9
by: Christopher Koh | last post by:
I will make a form which will search the database (just like google interface) that will look/match for the exact name in the records of a given fieldname. Any suggestions on how to make the code?
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
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
5
by: Fran Jakers | last post by:
Hello all, I'm new to all this and I could really use some help. I've searched the web but cannot find an answer. I have an HTML form with 3 radio buttons and a search field that calls a...
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...
12
by: iahamed | last post by:
Hi Everyone, I got two parts of my advance search to work, I am running out of Logic to connect the third. My mind is in swing! Pleaseeeeeeeee Help me. I have 3 Fiels to search, the First two...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.