Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access 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 January 17th, 2007, 02:32 PM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing Mulitiple pameters to a form query

ACCESS 2002 - Code query to use for text search
 At present I have a form "a00cQBFsubfrm-itemList1-0_gen2-qry2" this form contains a field [itemhds] which hold a text description & has a parameter in its query :-
Like "*"+"Menu-search prt2A]![Text_srt1]"+"*" Or "*"+[Forms]![a00aa Menu-search prt2A]![Text_srt2]+"*"
The parameters Text_srt1 & Text_srt2 on the form containing the code below (code example 1) and require words or part words entered by the user.

What I would like to do is remove the parameter in the query, & use VBA to set the where clause in the opened form, to this end I entered the code show in (code example 2) to attempt to do this, but received an error message “LAHC Inventory can’t find field ’|’ referred to in your expression”
PLEASE can any one give me a pointer in the right direction I need to take to make it work.
Colin

Code example 1
Private Sub Cndtxtsrch2code1_Click()
On Error GoTo Err_Cndtxtsrch2code1_Click
'test code 3 for text search

    Dim stDocName1 As String, strLNKcr1 As String

     stDocName1 = "a00cQBFsubfrm-itemList1-0_gen2-qry2"

        DoCmd.OpenForm stDocName1, , , strLNKcr1

Exit_Cndtxtsrch2code1_Click:
    Exit Sub

Err_Cndtxtsrch2code1_Click:
    MsgBox Err.Description
    Resume Exit_Cndtxtsrch2code1_Click

End Sub

Private Sub CndClearparameters_Click()
'Ja - Me!Text_srt1 = Null { current
'use inconjunction with Cndtxtsrch2code1 to clear parameter fields Text_srt1 & Text_srt2
        Me!Text_srt1 = Null
        Me!Text_srt2 = Null
End Sub
‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Code example 2

Private Sub Cndsrchcode1_Click()
On Error GoTo Err_Cndsrchcode1_Click
'test code 4 for search

    Dim stDocName As String, strLNKcr1 As String

    stDocName = "a00cQBFsubfrm-itemList1-0_gen2A-code"

    strLNKcr1 = [Selct2] = (itemhds Like " & " * " & Me.[Textsrt1] & " * "" & "" _
       Or itemhds Like " & " * " & Me.[Textsrt2] & " * "")

    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Cndsrchcode1_Click:
    Exit Sub

Err_Cndsrchcode1_Click:
    MsgBox Err.Description
    Resume Exit_Cndfrm2C_2_Click

End Sub
‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
Old January 18th, 2007, 08:27 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

<div align="left">Wow, I am not sure what code language that is.

In VBA, you would do this:

Dim stDocName As String, strLNKcr1 As String
Dim str1, str2 As String

str1 = Me.Textsrt1
str2 = Me.Txtsrt2

stDocName = "a00cQBFsubfrm-itemList1-0_gen2A-code"

strLNKcr1 = "[itemhds] Like " & "*" & str1 & "*" & _
       "Or [itemhds] Like " & "*" & str2 & "*"

    DoCmd.OpenForm stDocName, , , strLNKcr1

See if that works.
I generally put this sort of criteria in the query itself, and refer back to the text boxes on the form.</div id="left">

mmcdonal
 
Old January 19th, 2007, 03:05 PM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi mmcdona
Many thank for your code, I have tried it but get a error message " syntax error (missing operator) in query expression '[itemhds] like **Or[itemhds] Like **' " the code I enter was as follows

Private Sub Cndfrmsrchqry2_Click()
On Error GoTo Err_Cndfrmsrchqry2_Click
'a00cQBFsubfrm-itemList1-0_gen2-code1
    Dim stDocName As String
    Dim stLnkCr1 As String
    Dim stLnkCr2 As String
    Dim str1 As String
    Dim str2 As String

    str1 = Me!Text_srt1
    srt2 = Me!Text_srt2

    stDocName = "a00cQBFsubfrm-itemList1-0_gen2-code1"

    stLnkCr1 = "[itemhds] Like " & "*" & Srt1 & "*" & "Or [itemhds] Like " & "*" & Srt1 & "*"

    DoCmd.OpenForm stDocName, , , stLnkCr1
    'DoCmd.OpenForm stDocName, , , stLnkCr2

Exit_Cndfrmsrchqry2_Click:
    Exit Sub

Err_Cndfrmsrchqry2_Click:
    MsgBox Err.Description
    Resume Exit_Cndfrmsrchqry2_Click

End Sub
'end
 Can you help please
At the bottom of your message you say you would do this in the form you propose to open query, can you also tell me how you would obtain the above by that method,
the reason for doing it by code was so that I could give the user the option to choose "And" or " Or" between the parmeters, without using two different forms each with the appropriate query
Thank you for any help
Colin
 
Old January 19th, 2007, 03:25 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You can use a combo box to allow them to choose And or Or, then put that in line as well.

Use the query designer and change to SQL View to use the designer like SQL Query Analyzer to get your syntax working.

Here is the syntax for OR:

SELECT *
FROM tblYourTable
WHERE (((tblYourTable.YourColumn) Like "*yourstring1*" Or (tblYourTable.YourColumn) Like "*yourstring2*"));

To code this it would be:

"SELECT * FROM tblYourTable WHERE [YourColumn] Like " & "*" & str1 & "*" & " Or [YourColumn] Like " & "*" & str2 & "*"

If you added And/Or selection, take that as a variable from the combo box, and then try this:

sBool = Me.MyComboBox

"SELECT * FROM tblYourTable WHERE [YourColumn] Like " & "*" & str1 & "* " & sBool & " [YourColumn] Like " & "*" & str2 & "*"

Did that work?






mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
passing unique record from form to form Baconant Beginning VB 6 1 January 2nd, 2008 06:20 PM
Mulitiple/Nested IIF statements rohit_ghosh Access VBA 3 June 1st, 2007 10:44 AM
Prevent mulitiple logins in webgarden/farm senario amitjoshipune ASP.NET 1.0 and 1.1 Professional 4 August 18th, 2006 02:21 AM
mulitiple field query PLUS Durwood Edwards Classic ASP Databases 2 July 14th, 2005 10:54 AM
Passing Value from main form to Popup Form smartgir Access VBA 0 February 26th, 2004 06:26 PM





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