End If
' use this formatting for strings
If Len(Trim(Me.VTitle& vbNullString)) > 0 Then ' a better IsNull
strCriteria = strCriteria & " AND [VTitle] = '" & Trim (Me.VTitle) & "'"
End If
' use this formatting for Numbers
If IsNumeric(Me.windowquanty) Then ' a better IsNull
strCriteria = strCriteria & " AND [windowquanty] = " & Me.windowquanty
End If
'etc
'etc
' do this for as many fields you have on your form
'
'
' check to see if the user entered anything
If Not Len(Trim(strCriteria)) > 0 Then
MsgBox "Please enter in a search criteria."
Exit Sub
End If
' strip off the prefix in case the user had nothing for Date
strCriteria = RemovePrefix(strLogicalOperator, strCriteria)
' check for matching records
If DCount("*", "[YourTableName]", strCriteria) = 0 then
MsgBox "There are no records which match your criteria. Try Again.
Exit Sub
End If
DoCmd.Close ' close this form
' open the form with the query results
DoCmd.OpenForm "YourFormName", , , strCriteria
.......................................................... .................
here's the code for the "RemovePrefix" function:
Public Function RemovePrefix(strPrefix As String, strEntireString As String)
As String
Dim strReturnedString As String, intStringLength As Integer, intPrefixLength
As Integer
' strips off the prefix from the string , if present
intPrefixLength = Len(strPrefix)
strReturnedString = Trim(strEntireString)
intStringLength = Len(strReturnedString)
If intPrefixLength < intStringLength Then
If Left(strReturnedString, intPrefixLength) = strPrefix Then
strReturnedString = Right(strReturnedString, intStringLength -
intPrefixLength)
strReturnedString = Trim(strReturnedString)
End If
End If
RemovePrefix = strReturnedString
End Function
Hi there treebeard...
I cannot find that "Searching Tables" post...
PLease could you either advise me on what I need to do? or
could you be so kind as you copy your reply into this
thread please?
How do I use a command button to utilise that filter thing
you were on about but by using the text box on my form?
Would this open in a sub form or the current window? as I
would like it to open a form and display the results so
that they can see there results. then if they want to
scroll through the list then they can just close the open
form stating there results of there search...
Can this be done?
Many Thanks
James
Many Thanks
James
-----Original Message-----
message
Hi I have some tables and in each one I have diffrent
things for example one maybe DVD's annother maybe
CD's....
I have certain forms which display them... I would like
these forms to be able to search through the table that
the form is based on so it would be searching through
the
DVD table if the form was based on it... its just a
simple
thing so that the user can search the records listed
rather than scroll through them all...
Is there a way I could do this???
Then could you tell me how I display my results in a
subform please... I would like it so that if the user
types in something like ra* and them can get things like
Rambo1, Rambo2, Rambo3,Ransom etc... so I would like to
excorporate the Wildcard (*).
Many Thanks
James
James,
There's already a built-in search and filter capability
in access forms. If
you right-click on any field, and enter , for
example, "ra*" into the title
field, this will bring up all titles that start with ra.
Depending on the technical ability of your users , this
may or may not be
sufficient. In many cases we have to build customized
search forms. If you
scroll down , you'll see my response to "searching Tables"
Jack
.
.