473,421 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

Access Multiple Criteria OpenForm

Greeting,

I'm trying to launch an OpenForm function with a double criteria. I
can't seem to make them work together, the two criteria work seperatly
so I assume my code to synchronise both together isn't working.

The idea is to open a form that will sum sales per month. I wish to
have the form filtered on open by year and by currency.

Here's my code:

Private Sub Commande13_Click()

Dim stDocName, var1, var2 As String
Dim stLinkCriteria As String

If IsNull(Me.Combo1) Or Me.Combo1 = "" Then
var1 = " "
Else
var1 = "CAPYear=" & Me.Combo1
End If
If IsNull(Me.Combo2) Or Me.Combo2 = "" Then
var2 = " "
Else
var2 = "CAPCurrency=" & "'" & Me.Combo2 & "'"
End If

stLinkCriteria = var1 + var2
' (I've tried using AND instead but I get an incompatibility error,
probably numeric VS Text)

stDocName = "FRM_MonthSales"

DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Commande13_Click:
Exit Sub
Err_Commande13_Click:
MsgBox Err.Description
Resume Exit_Commande13_Click
End Sub

Thank for all the help!!!

Nov 23 '05 #1
4 3560

"Beejer" <bj********@yahoo.ca> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Greeting,

I'm trying to launch an OpenForm function with a double criteria. I
can't seem to make them work together, the two criteria work seperatly
so I assume my code to synchronise both together isn't working.

The idea is to open a form that will sum sales per month. I wish to
have the form filtered on open by year and by currency.

Here's my code:

Private Sub Commande13_Click()

Dim stDocName, var1, var2 As String
Dim stLinkCriteria As String

If IsNull(Me.Combo1) Or Me.Combo1 = "" Then
var1 = " "
Else
var1 = "CAPYear=" & Me.Combo1
End If
If IsNull(Me.Combo2) Or Me.Combo2 = "" Then
var2 = " "
Else
var2 = "CAPCurrency=" & "'" & Me.Combo2 & "'"
End If

stLinkCriteria = var1 + var2
Try something like this

if var1 <> " " then
strLinkCriteria = var1
if var2 <> " " then
strLinkCriteria = strLinkCriterial & " AND " & var2
endif
else
if var2 <> " " then
strLinkCriteria = var2
endif
endif

You may need to add some parentheses around your criteria.
' (I've tried using AND instead but I get an incompatibility error,
probably numeric VS Text)

stDocName = "FRM_MonthSales"

DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Commande13_Click:
Exit Sub
Err_Commande13_Click:
MsgBox Err.Description
Resume Exit_Commande13_Click
End Sub

Thank for all the help!!!

Nov 23 '05 #2
I've added your suggestion and it worked very nicely. Didn't have to
add anything to it except correct the typo in :

strLinkCriterial & " AND " & var2

by removing the "l" in strLinkCriteria

Thanks

Beejer

Nov 25 '05 #3
Glad I could help
The compiler does a good job finding typos!
A good reason to use Option Explicit.

"Beejer" <bj********@yahoo.ca> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I've added your suggestion and it worked very nicely. Didn't have to
add anything to it except correct the typo in :

strLinkCriterial & " AND " & var2

by removing the "l" in strLinkCriteria

Thanks

Beejer

Nov 28 '05 #4
And along the same lines but in a different manner here's something I
put together that may give you some ideas about making time periods and
other criteria dynamic.

The free downloadable sample database at www.bullschmidt.com/access
uses the query by form concept so that on the invoices dialog one can
optionally choose a rep, a customer, and perhaps a date range, click on
a button that says "Input," and then have the invoice form open up
showing all the invoices that match the criteria.

Best regards,
J. Paul Schmidt, Freelance Web and Database Developer
http://www.Bullschmidt.com
Access Database Sample, Web Database Sample, ASP Design Tips

Nov 29 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: nospam | last post by:
Am I trying to do something that is impossible with access 97? I want to write an address book application. I have exported (from a Casio BOSS organiser) all my contact information and it is...
3
by: David | last post by:
Hello, hope someone can help. I have a request to print word .doc check lists with selected records in Access for surgery procedure cards. I have hyperlinked the word doc's to a field in each...
3
by: MartinR | last post by:
Hi, I'm still new to writing code in vba as I've only been introduced to access three weeks ago. I have written this code below and it executes but does not do what I want it to do. What I want is...
6
by: keri | last post by:
I am trying to; Click on a textbox in a form called frmcalendar to open another form petalplanning (I can do that bit). However I want the form to open at a certain record depending on the date...
1
by: mchlle | last post by:
I need for a form to display certain records based on the user. If current user = user1 or user2 then open frmNotesAll If current user = user 3 then open frmNotes where counselor id = 2 or 6 or...
9
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result...
0
MMcCarthy
by: MMcCarthy | last post by:
The more data you include in your tables the more you will need to have indexes to search and sort that data. However, there is a balance between having enough indexes and too many. Too many...
5
by: Brett | last post by:
Hello, Is it possible to have just one criteria and have it apply to a group of queries? I am trying to create a report with the separate results of 4 queries based on a prompt for the user...
14
by: SimeonD | last post by:
Hi I have an access database called Sales.Mdb In vb.net 2005, I'd like to open it. Which I can do. What I can't figure out is how to figure out if Sales.Mdb is open already. If so, I want to open...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.