Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 31st, 2004, 03:36 PM
labamba labamba is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 17 labamba User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
MS Access query with VB

Hi there!

I am trying to write a VB app in which the user should enter some search strings, which will search the database for matches, and the result will then be retuned to the user (via the app of course)

(ie. string=orange juice and it will return all the people that like the orange juice)

Can you please help me by giving me an example code of such a search query or maybe to suggest me site?

Thanks a lot

Reply With Quote
  #2  
Old January 31st, 2004, 05:54 PM
Memnoch's Avatar
Memnoch Memnoch is online now
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,879 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 18 h 10 m 33 sec
Reputation Power: 500
You have provided very little information. It would be easier to help you, if you posted database info like tablenames, field names, names of controls on your form, etc...

But to search a database for text a user entered on a form you could just run a sql query like the one below.
Code:
SELECT * FROM TableName WHERE fieldName LIKE '" & txtSearch.Text & "*'

Last edited by Memnoch : January 31st, 2004 at 05:56 PM.

Reply With Quote
  #3  
Old January 31st, 2004, 06:14 PM
labamba labamba is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 17 labamba User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thasks, I am new to VB and i am now trying to find what is going on.

I have a database with a table called 'Customers' and 3 fields 'customer_name', 'customer_email', 'shop_id'

I want to build an app which will just show on the screen all the records (all three fields) that have the same 'shop_id' value.

In the application, this 'shop_id' value will be defined by the user.

i.e. An .exe with a 'search' button (which will search for all the matches for the field 'shop_id') and will display all the customers' name and customers' email that have the same shop_id.

I hope now it's more clear

Reply With Quote
  #4  
Old January 31st, 2004, 08:24 PM
Memnoch's Avatar
Memnoch Memnoch is online now
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,879 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 18 h 10 m 33 sec
Reputation Power: 500
Okay, so what exactly is the question?
If you are wanting to know how to query the database, just modify the sql statement above to something like this
Code:
SELECT * FROM Customers WHERE shop_id = " & txtShopId.Text 


I'm not really sure what you're asking though, it seems as if you want someone to create this application for you???

Reply With Quote
  #5  
Old February 1st, 2004, 06:25 AM
labamba labamba is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 17 labamba User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
the code is this:

frmMain
Private Sub cmdSQL_Click()
Dim MsgText As String
'display in Grid
HflXRecords.Clear
Set HflXRecords.DataSource = _
ExecuteSQL(txtSQl, MsgText)
sbrStatus.Panels(1).Text = MsgText
End Sub

Private Sub HflXRecords_Click()

End Sub

Seperate module:

Public Function ExecuteSQL(ByVal SQL _
As String, MsgString As String) _
As ADODB.Recordset
'executes SQL and returns Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sTokens() As String

On Error GoTo ExecuteSQL_Error

sTokens = Split(SQL)
Set cnn = New ADODB.Connection
cnn.Open ConnectString
If InStr("INSERT,DELETE,UPDATE", _
UCase$(sTokens(0))) Then
cnn.Execute SQL
MsgString = sTokens(0) & _
" query successful"
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, _
adOpenKeyset, _
adLockOptimistic
rst.MoveLast 'get RecordCount
Set ExecuteSQL = rst
MsgString = rst.RecordCount & _
" records found from SQL"
End If
ExecuteSQL_Exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function

ExecuteSQL_Error:
MsgString = "ExecuteSQL Error: " & _
Err.Description
Resume ExecuteSQL_Exit
End Function

Public Function ConnectString() _
As String
'returns a DB ConnectString
ConnectString = "Provider=" & _
"Microsoft.Jet.OLEDB." & _
"4.0;Data Source=" & _
App.Path & "\database.mdb"
End Function


And my question is:

Should I get out the IF ELSE statements and replace them with the code that u said?

Or maybe I should not use the module (except for the database connetion) and just use the frmMain with your code?

And if so, what where should I put it?

Last edited by labamba : February 1st, 2004 at 09:14 AM.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > MS Access query with VB


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT