Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > Parameter Queries


Reply
 
Thread Tools Display Modes
  #1  
Old 03-30-2004, 07:41 AM
benjammin benjammin is offline
Freshman
 
Join Date: Feb 2004
Posts: 29
Default Parameter Queries


Is it possible to have a parameter query where the user can enter nothing so that there is no criteria.
For example i have a query for properties where two windows pop up, one for you to enter a desired town, and one for area. I would like to have it so that you could just enter a town for example and leave the area blank to show all of the properties in that one town. Is this possible? and if so how would i do it?
Reply With Quote
  #2  
Old 03-30-2004, 07:43 AM
MKoslof's Avatar
MKoslof MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Write a function that implements your query. Make one of the parameters optional, meaning it does not have to filled in..such as:

Code:
Public Function runSQL (ByVal strString as string, Optional strChoice as string) End Function
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #3  
Old 03-30-2004, 09:14 AM
benjammin benjammin is offline
Freshman
 
Join Date: Feb 2004
Posts: 29
Default

Quote:
Originally Posted by MKoslof
Write a function that implements your query. Make one of the parameters optional, meaning it does not have to filled in..such as:

Code:
Public Function runSQL (ByVal strString as string, Optional strChoice as string) End Function

Sorry im a bit of a novice could you give me that in simple access terms lol.
Reply With Quote
  #4  
Old 03-30-2004, 09:21 AM
MKoslof's Avatar
MKoslof MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

This is very raw...you need to build your own robust function.Just an example of how this *could* work. You need to handle how this query is really built, all your ADO connection properties and concerns(checking if the connection is already open, validing your records, if you need a recordset object for standard selects, etc.)...I won't do it all for you

Code:
Public Function runSQL(ByVal strString as string, Optional strChoice as String) Dim sSQL as string Dim cn as ADODB connection Set cn = New ADODB.connection cn.connectionString = "yourConnectionString" cn.Open If strChoice <> "" Then sSQL = "DELETE * FROM myTable WHERE field1 = '" & strString & "' AND field2 = '" & strChoice & "'" Else sSQL = "DELETE * FROM myTable WHERE field1 = '" & strString & "'" End If cn.execute sSQL cn.close Set cn = Nothing End Function
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parameter Query in Access run in VBA: how to NOT use a parameter spitzmuller Word, PowerPoint, Outlook, and Other Office Products 0 10-01-2003 08:35 AM
Queries from Queries from Queries – General Question. Sanders720 Database and Reporting 2 05-29-2003 07:46 AM
Excel Chart With Access Parameter Query davencharleston Word, PowerPoint, Outlook, and Other Office Products 11 04-23-2003 09:36 AM
Parameter Question yaminz Database and Reporting 0 03-17-2003 07:29 AM
Calling a Parameter Query From another Query T_im2 Database and Reporting 2 02-12-2003 01:56 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->