Go Back   Access World Forums > Apps and Windows > Visual Basic

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 08-11-2017, 01:32 AM   #1
comep
Newly Registered User
 
Join Date: Mar 2017
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
comep is on a distinguished road
Search using Combo Box and Filter the results in text boxes

Dears

I am trying to do a small program on VB 6.0 to find the records in database and print it in text box based on combo box selection but i failed to find a code which allow me to do this.

Any help please.

comep is offline   Reply With Quote
Old 08-11-2017, 02:57 AM   #2
Ranman256
Newly Registered User
 
Join Date: Apr 2015
Location: KY,USA
Posts: 2,398
Thanks: 0
Thanked 517 Times in 503 Posts
Ranman256 is on a distinguished road
Re: Search using Combo Box and Filter the results in text boxes

you need to use database connection control to connect to the database.
(that or ADO connection code)

then use that to connect textbox to the db control.
Ranman256 is offline   Reply With Quote
Old 08-11-2017, 04:46 AM   #3
comep
Newly Registered User
 
Join Date: Mar 2017
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
comep is on a distinguished road
Re: Search using Combo Box and Filter the results in text boxes

Quote:
Originally Posted by Ranman256 View Post
you need to use database connection control to connect to the database.
(that or ADO connection code)

then use that to connect textbox to the db control.
Thanks for your help but could you please assist me with a code to connect to database as i am using database with extension .accdb and all codes available is for mdb database.

Note : I want to use a code to connect to database.

comep is offline   Reply With Quote
Old 08-11-2017, 08:43 PM   #4
comep
Newly Registered User
 
Join Date: Mar 2017
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
comep is on a distinguished road
Re: Search using Combo Box and Filter the results in text boxes

Any help please
comep is offline   Reply With Quote
Old 08-11-2017, 09:04 PM   #5
arnelgp
Newly Registered User
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 3,400
Thanks: 22
Thanked 1,155 Times in 1,091 Posts
arnelgp has a spectacular aura about arnelgp has a spectacular aura about
Re: Search using Combo Box and Filter the results in text boxes

here is a small script:

Quote:
Dim adoCon
Dim adoRs
Dim strSQL As String


Dim strDB As String

'Change YourDatabaseName to actual database you have
strDB = "c:\path\YourDatabaseName.accdb"



Set adoCon = CreateObject("ADODB.Connection")
adoCon.Open "Provider = Microsoft.ACE.OLEDB.12.0; " & _
"Data Source = " & strDB & ";" & _
"Persist Security Info = False;"

'Change Table1 to your table name in MS Access
'change the name of combobox and the fieldname in MS Access table
'
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''
' if combo is numeric
strSQL = "SELECT [fieldNameToReturn] FROM Table1 Where [fieldName] = " + [combo].Value + ";"

' if combo is text
'strSQL = "SELECT [fieldNameToReturn] FROM Table1 Where [fieldName] = '" + [combo].Value + "';"
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''

Set adoRs = CreateObject("ADODB.Recordset")

'Set the cursor type we are using so we can navigate through the recordset
adoRs.CursorType = 2

'Set the lock type so that the record is locked by ADO when it is updated
adoRs.LockType = 3

'Open the tblComments table using the SQL query held in the strSQL varaiable
'adoRs.Open strSQL, adoCon

If Not adoRS.Eof() Then
[yourTextBox] = adoRs(0)
End If
adoRs.Close
adoCon.Close
Set adoRs = Nothing
Set adoCon = Nothing
__________________
"Never stop learning, because life never stops teaching"

Last edited by arnelgp; 08-11-2017 at 09:09 PM.
arnelgp is offline   Reply With Quote
Old 08-11-2017, 10:06 PM   #6
comep
Newly Registered User
 
Join Date: Mar 2017
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
comep is on a distinguished road
Re: Search using Combo Box and Filter the results in text boxes

Quote:
Originally Posted by arnelgp View Post
here is a small script:
Thanks but there is an error returned: invalid outside procedure , what that means ?
comep is offline   Reply With Quote
Old 08-11-2017, 10:31 PM   #7
arnelgp
Newly Registered User
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 3,400
Thanks: 22
Thanked 1,155 Times in 1,091 Posts
arnelgp has a spectacular aura about arnelgp has a spectacular aura about
Re: Search using Combo Box and Filter the results in text boxes

insert the code in your Combo's SelectedValueChanged Event.

you should modify also this:

Quote:
strSQL="SELECT [fieldNameToReturn] FROM Table1 Where [fieldName]='" + [combo].Value + "';"
TO:
Quote:
strSQL="SELECT [fieldNameToReturn] FROM Table1 Where [fieldName]='" + Me.combo.ToString + "';"
also this one:
[qoute]
[yourTextBox]=adoRs(0)
[/quote]
TO:
Quote:
Me.yourTextBox.Text = adoRs.Fields(0).Value

__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 08-11-2017, 10:35 PM   #8
comep
Newly Registered User
 
Join Date: Mar 2017
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
comep is on a distinguished road
Re: Search using Combo Box and Filter the results in text boxes

Quote:
Originally Posted by arnelgp View Post
insert the code in your Combo's SelectedValueChanged Event.

you should modify also this:


TO:


also this one:
[qoute]
[yourTextBox]=adoRs(0)
TO:[/QUOTE]

Thanks its worked but which code should be modified to show values in combobox
comep is offline   Reply With Quote
Old 08-12-2017, 04:22 AM   #9
comep
Newly Registered User
 
Join Date: Mar 2017
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
comep is on a distinguished road
Re: Search using Combo Box and Filter the results in text boxes

Any help please
comep is offline   Reply With Quote
Old 08-12-2017, 05:06 AM   #10
arnelgp
Newly Registered User
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 3,400
Thanks: 22
Thanked 1,155 Times in 1,091 Posts
arnelgp has a spectacular aura about arnelgp has a spectacular aura about
Re: Search using Combo Box and Filter the results in text boxes

What do you mean "show value in combobox"?
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 08-12-2017, 09:41 AM   #11
comep
Newly Registered User
 
Join Date: Mar 2017
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
comep is on a distinguished road
Re: Search using Combo Box and Filter the results in text boxes

The program should be work as below :-

- Retrieve all Users ID in combobox where the Users ID is a field on the database.
- Choose User ID from combobox after that the values which related to that user ID should be listed in text box .

Hope this clarify my enquiry
comep is offline   Reply With Quote
Old 08-13-2017, 06:20 AM   #12
comep
Newly Registered User
 
Join Date: Mar 2017
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
comep is on a distinguished road
Re: Search using Combo Box and Filter the results in text boxes

any help please

comep is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi Combo Box Search - Clearing filter to show all results teachme Forms 3 06-01-2016 11:02 AM
Multiple combo boxes and text boxes on a search form pabloUSA Queries 2 04-17-2014 05:50 AM
Multiple Combo boxes and text boxes to search record on Access form pabloUSA Forms 0 03-24-2014 03:19 AM
[SOLVED] Filter text boxes by two combo box values mikey71174 Forms 3 08-06-2013 12:03 PM
Multi Combo Boxes - Filter results, but show all when blank. macca72 Forms 2 09-01-2011 11:39 PM




All times are GMT -8. The time now is 02:12 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World