Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 8th, 2004, 09:47 AM
kmarti33 kmarti33 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 6 kmarti33 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
VB Filters using SQL in Access 2000

I am trying to make an Access 2000 database user friendly. I want to apply filters on the database. What I want to do is have the user select a field from a drop down box, then enter a value, and have the filter display all records in a set range. So far I have started a Module that lets the user pick a field, and prompts for a value. I then am trying to apply a filter via VB, but I don't know how to display it, here is what I have so far.

Function Main()
Dim n, pnum As Integer
Dim d, od, bore As Double
Dim prompt, title, default, invalue
Dim dbload As Database
Dim rsload As DAO.Recordset
Dim sload As String

prompt = "Sort by Part Number, Wheel OD, or Bore 1:"
title = "Sort by User Value"
default = "Part Number"
invalue = InputBox(prompt, title, default)
sload = "SELECT * FROM ALL_LOADWHEELS;"
Set dbload = CurrentDb()
Set rsload = dbload.OpenRecordset(sload, dbOpenDynaset)
If invalue = "Part Number" Then
pnum = InputBox("Enter the Part Number.", , 0)
rsload.Filter = "PART_NUMBER = pnum"
MsgBox "You chose the Part Number " & pnum & "."
End If
rsload.Close
dbload.Close
End Function

I have 2 problems.
1. How do I switch the MsgBox for invalue to a dropdown box where the values are Field Names?
2. How do I display my filter? I tried rsload.FilterOn = True, but it wasn't found.

Reply With Quote
  #2  
Old July 8th, 2004, 05:54 PM
ineuw ineuw is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 82 ineuw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 30 m 28 sec
Reputation Power: 5
1. How do I switch the MsgBox for invalue to a dropdown box where the values are Field Names?

You can't - use a form with combo box and select field list of a table for the row source.

2. How do I display my filter? I tried rsload.FilterOn = True, but it wasn't found.

Forget filtering. Build the SQL string after all values are selected and/or specified. This could be a parameter SQL or similar (there are more ways to skin a cat).

Create the recordset after the string is complete for results display or whatever.

Reply With Quote
  #3  
Old July 9th, 2004, 02:22 PM
kmarti33 kmarti33 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 6 kmarti33 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ok I decided to use a form instead. Now I am trying to populate a list box with a RowSourceType function. My function however is not working and I am getting the following error.

'SearchResults()' may not be a valid setting for the RowSourceType property, or there was a compile error in the function.

Here is my function:


Function SearchResults(fld As Control, id As Variant, _
row As Variant, col As Variant, _
code As Variant) As Variant

Dim Search As Variant
Select Case code
Case acLBInitialize ' Initialize.
Search = "Select * From ALL_LOADWHEELS;"
Case acLBOpen ' Open.
Search = Timer
Case acLBGetRowCount ' Get rows.
Search = -1
Case acLBGetColumnCount ' Get columns.
Search = 33
Case acLBGetColumnWidth ' Get column width.
Search = -1
Case acLBGetValue ' Get the data.
Search = "Select * From ALL_LOADWHEELS;"
End Select
SearchResults = Search
End Function

I am going to eventually add more to the GetValue part, but I am just trying to get this basic search to work.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > VB Filters using SQL in Access 2000


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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway