I'm using this Select Case code in conjunction with a Option Group on a multi-tab form with about 40 run report buttons. The code works fine when included in the Click Event code of a button. I would like to convert it to a function for obvious reasons. I have tried a few variation of a function with no success. What is the best approach for converting a procedure to a function. -
Private Sub WhatYear()
-
Dim strCriteria As String
-
Select Case Me.Seasons
-
Case 2009
-
strCriteria = "[ExpDate] Between #09/01/2009# and #09/01/2010#"
-
Case 2010
-
strCriteria = "[ExpDate] Between #09/01/2010# and #09/01/2011#"
-
Case 2011
-
strCriteria = "[ExpDate] Between #09/01/2011# and #09/01/2012#"
-
End Select
-
-
DoCmd.OpenReport "rptWeeklyStatus_Asia_Qry", acViewPreview, , strCriteria
-
Thanks for any and all suggestions
Gil
9 1359 - Copy-N-Paste the following Code into the Declarations Section of the Form's Code Module. This must be the Form that contains the [Seasons] and [Expdate] Fields, and the Function should be declared Privately. Notice a couple of minor additions to the Code also.
- Private Function fWhatYear()
-
Dim strCriteria As String
-
-
If IsNull(Me.Seasons) Or Not IsNumeric(Me.Seasons) Then Exit Function
-
-
Select Case Me.Seasons
-
Case 2009
-
strCriteria = "[ExpDate] Between #09/01/2009# and #09/01/2010#"
-
Case 2010
-
strCriteria = "[ExpDate] Between #09/01/2010# and #09/01/2011#"
-
Case 2011
-
strCriteria = "[ExpDate] Between #09/01/2011# and #09/01/2012#"
-
Case Else
-
MsgBox "No Report exists for the specified Year", vbExclamation, "Invalid Year"
-
Exit Function
-
End Select
-
-
DoCmd.OpenReport "rptWeeklyStatus_Asia_Qry", acViewPreview, , strCriteria
-
End Function
- To Execute the Function:
ADezii,
Thanks for the prompt response.
I added your changed code as a private function of the form code module. Selecting a different year still has no effect on the date range of the report.
[code]
Private Function fWhatYear()
Dim strCriteria As String
If IsNull(Me.Seasons) Then Exit Function
Select Case Me.Seasons
Case 2009
strCriteria = "[ExpDate] Between #09/01/2009# and #09/01/2010#"
Case 2010
strCriteria = "[ExpDate] Between #09/01/2010# and #09/01/2011#"
Case 2011
strCriteria = "[ExpDate] Between #09/01/2011# and #09/01/2012#"
Case Else
MsgBox "No Report exists for the specified Year", vbExclamation, "Invalid Date Range"
Exit Function
End Select
End Function
--------------------------------------------------------------------------------
Private Sub cmdAsiaBillOfLadingCount_Click()
On Error GoTo cmdAsiaBillOfLadingCount_Click_Err
fWhatYear
DoCmd.OpenReport "rptBillOfLadingCount_Asia_Tbl", acViewPreview, , strCriteria
PrintQuestion
cmdAsiaBillOfLadingCount_Click_Exit:
Exit Sub
cmdAsiaBillOfLadingCount_Click_Err:
MsgBox Error$
Resume cmdAsiaBillOfLadingCount_Click_Exit
End Sub
I saw where included the DoCmd.OpenReport "rptWeeklyStatus_Asia_Qry", acViewPreview, , strCriteria in the function, Was that your intension?
It's part of Click Event code, I included it as a reference to how srtCriteria is being used. Sorry for a confusion.
Gil
I saw where included the DoCmd.OpenReport "rptWeeklyStatus_Asia_Qry", acViewPreview, , strCriteria in the function, Was that your intension?
My fault, thought that it may be part of the overall Code, thus the inclusion. Also forgot about the Option Group, that's what happens as you get older ! (LOL)
No problem, I deal with the same problem.
So, Do you have any other suggestions on how to convert
this code to a function? Or should I just add it to each button?
Gil
What code are you referring to, Gil?
The "WhatYear" function code.
The changes you suggested did not work.
Code has been tested prior to Posting and does work.
Sorry but I'm confused again!
Did you test the code with or without the DoCmd.OpenReport & the Option Group?
Move the Declaration for strCriteria from the Function to the Form's Code Module, General Declarations Section. - 'Should be in the General Declarations Section of the involved Form
-
Dim strCriteria As String
Sign in to post your reply or Sign up for a free account.
Similar topics
by: jr |
last post by:
Sorry for this very dumb question, but I've clearly got a long way to go!
Can someone please help me pass an array into a function. Here's a starting
point.
void TheMainFunc()
{
// Body of...
|
by: Sweety |
last post by:
hi,
Is main function address is 657.
its show in all compiler.
try it & say why?
bye,
|
by: Terry |
last post by:
I am converting (attempting) some vb6 code that makes vast use of interfaces.
One of the major uses is to be able to split out Read-only access to an
obect. Let me give you a simple (contrived)...
|
by: Beta What |
last post by:
Hello,
I have a question about casting a function pointer. Say I want to make
a generic module (say some ADT implementation) that requires a function
pointer from the 'actual/other modules'...
|
by: infogoogle |
last post by:
Hello,
i'm having problems with the type of a template function:
This code:
class A {};
class B : A {};
template<class T B* fnull() { return 0; };
|
by: Robert Seacord |
last post by:
i am trying to print the address of a function without getting a
compiler warning (i am compiling with gcc with alot of flags).
if i try this:
printf("%p", f);
i get:
warning: format %p...
|
by: Noah Roberts |
last post by:
Trying to use boost::function in a C++/CLI program. Here is code:
pragma once
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <vector>
using namespace System;
|
by: linarin |
last post by:
#include <iostream>
using namespace std;
typedef bool (*CallableFunction)(int argc,char* argv);
void DefineMyFunction(const char* name,CallableFunction func){
//here do the define action.
}...
|
by: copx |
last post by:
Why doesn't the C standard include generic function pointers?
I use function pointers a lot and the lack of generic ones is not so cool.
There is a common compiler extension (supported by GCC...
|
by: Ali |
last post by:
This code below works with M$ VS2005 but fails with g++ 4.1.3.
However, the unary operation works with g++ as well.
The interval class is at http://xsc.de but everything is declared as
it...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
| |