Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 15th, 2003, 03:10 AM
Registered User
 
Join Date: Nov 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default mask of search with fields checkbox

Hi, I have one search mask I give in one access table . The code is in a click event of open a result mask; the control are checkbox fun1,fun2,fun3...funx and I would want to only select some of they for a research; for example:

fun1=yes
fun3=yes
fun5=yes

the table=numsist
the search mask=ricercafunzioni
the result mask=numsistema
the fields of table=funz1,funz2,funz3,....funzx

this is my code in a click event:

Private Sub cercarec_Click()
Dim Name As String
Dim Criteria As String
Criteria = "select * from numsist where funz1 like
        nz([forms]![ricercafunzioni]![fun1];" * ") AND funz2 like
        nz([forms]![ricercafunzioni]![fun2];" * ") AND funz3 like
        nz([forms]![ricercafunzioni]![fun3];" * ") AND funz4 like
        nz([forms]![ricercafunzioni]![fun4];" * ") AND funz5 like
        nz([forms]![ricercafunzioni]![fun5];" * ") AND funz6 like
        nz([forms]![ricercafunzioni]![fun6];" * ") AND funz7 like
        nz([forms]![ricercafunzioni]![fun7];" * ") AND funz8 like
        nz([forms]![ricercafunzioni]![fun8];" * ") AND funz9 like
        nz([forms]![ricercafunzioni]![fun9];" * ") AND funz10 like
        nz([forms]![ricercafunzioni]![fun10];" * ")"
        Name = "numsistema"
        DoCmd.OpenForm Name, , , Criteria
End Sub

this code does not work and it gives back the following error:

error 13 - type not correspondent

which it is the error?

thanks

Frank



 
Old November 16th, 2003, 12:14 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

try reform the criteria text as follows

Criteria = "select * from numsist where funz1 like '" & nz([forms]![ricercafunzioni]![fun1]) & "*' AND" & .....

Ahmed Ali
Software Developer
 
Old November 17th, 2003, 02:27 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

The problem is with the quotation marks. They're confusing Access because it doesn't know what is the string Criteria vs. what is inside the NZ function. Substitute the all quotation marks ( " ) in your NZ functions with single quotes ( ' ). That is:

Criteria = "select * from numsist where funz1 like
        nz([forms]![ricercafunzioni]![fun1];' * ') AND funz2 like
        nz([forms]![ricercafunzioni]![fun2];' * ') AND funz3 like
        nz([forms]![ricercafunzioni]![fun3];' * ') AND funz4 like
        nz([forms]![ricercafunzioni]![fun4];' * ') AND funz5 like
        nz([forms]![ricercafunzioni]![fun5];' * ') AND funz6 like
        nz([forms]![ricercafunzioni]![fun6];' * ') AND funz7 like
        nz([forms]![ricercafunzioni]![fun7];' * ') AND funz8 like
        nz([forms]![ricercafunzioni]![fun8];' * ') AND funz9 like
        nz([forms]![ricercafunzioni]![fun9];' * ') AND funz10 like
        nz([forms]![ricercafunzioni]![fun10];' * ')"

In other words, the quotes are only used to identify the string.

Criteria = " some expression ", or
Criteria = " some expression = ' some string ' "

Notice that it's ' some string ' and not " some string " because those extra " marks will confuse Access. It will think

Criteria = " some expression = " and lop off the rest of it, misinterpret it, and give you an error.

Examples of statements

Criteria = "Select * MyTable WHERE MyTextField = 'Jones'"
Criteria = "Select * MyTable WHERE MyTextField = '" & Me.txtName & "'"
Criteria = "Select * MyTable WHERE MyTextField Like '*Jones*'"
Criteria = "Select * MyTable WHERE MyNumField > 0"
Criteria = "Select * MyTable WHERE MyNumField > " & Me.txtNumber



Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division





Similar Threads
Thread Thread Starter Forum Replies Last Post
Want to Search Several Fields for the Same Keyword Eyrehead Access 3 March 16th, 2007 11:08 AM
retrieving fields,and using search button louie001 Beginning VB 6 0 October 11th, 2005 04:32 AM
Search and display fields in XML file kts_33 XML 5 September 28th, 2004 08:17 AM
Search and display fields in XML file kts_33 Classic ASP XML 1 September 22nd, 2004 05:16 AM
Multiple Fields Search Helmut Classic ASP Databases 4 July 15th, 2003 02:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.