473,396 Members | 1,933 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,396 software developers and data experts.

Function Help

Background:
I have a table of fields each field representing a month (Jan, Feb,
Mar...). These are not a date field but more of a bucket to hold
labor actuals. Along with the months their is another field for
year. Looking at the table you can see which month and which year the
hours belong to but since the month buckets are not actual dates it is
hard to write certain criteria's that represent dates. I have linked
to a suppliers database and that is why it is this way (not something
i created).

Problem:
What i need is to write a parameter function that would allow me to
see only the dates that are greater than a parameter value.

My not so good VB skills solution (need help finishing):
I thought that i could do a select case that would look something like
this. I would have a combo box for month (cboMonth) and combo box for
year (cboYear).

Case1: Jan+Feb+Mar+Apr...
Case2: Feb+Mar+Apr+May...
Case3: Mar+Apr+May+Jun...
Case4: Apr+May+Jun+Jul...

If CboMonth = "Jan" then
Case1 where [Year] >= cboYear
If CboMonth = "Feb" then
Case2 where year = cboYear + Case1 where [year] cboYear
If CboMonth = "Mar" then
Case3 where year =cboYear + Case1 where [year] cboYear
....

First question - how close am i on the code? Am i on the right
track?
Second Question - If i save this as a function and call it in a query
how does it work to get the parameters that are on my form? Really i
need someone to fill the gaps of how to do this. i really suck at the
VB side of Access.

Any help would be awesome.

KO

Dec 12 '07 #1
5 2036
On Dec 12, 10:32 am, turtle <kol...@vistacontrols.comwrote:
Background:
I have a table of fields each field representing a month (Jan, Feb,
Mar...). These are not a date field but more of a bucket to hold
labor actuals. Along with the months their is another field for
year. Looking at the table you can see which month and which year the
hours belong to but since the month buckets are not actual dates it is
hard to write certain criteria's that represent dates. I have linked
to a suppliers database and that is why it is this way (not something
i created).

Problem:
What i need is to write a parameter function that would allow me to
see only the dates that are greater than a parameter value.

My not so good VB skills solution (need help finishing):
I thought that i could do a select case that would look something like
this. I would have a combo box for month (cboMonth) and combo box for
year (cboYear).

Case1: Jan+Feb+Mar+Apr...
Case2: Feb+Mar+Apr+May...
Case3: Mar+Apr+May+Jun...
Case4: Apr+May+Jun+Jul...

If CboMonth = "Jan" then
Case1 where [Year] >= cboYear
If CboMonth = "Feb" then
Case2 where year = cboYear + Case1 where [year] cboYear
If CboMonth = "Mar" then
Case3 where year =cboYear + Case1 where [year] cboYear
...

First question - how close am i on the code? Am i on the right
track?
Second Question - If i save this as a function and call it in a query
how does it work to get the parameters that are on my form? Really i
need someone to fill the gaps of how to do this. i really suck at the
VB side of Access.

Any help would be awesome.

KO

Maybe u need something like this?...

Public Function GetStartDate() As Date
Dim iMonth%, iYr%
Dim dtStartDate As Date

On Error GoTo Err_GetStartDate

iYr = CInt(cboYear.Value)
iMonth = GetMonthNumFromSelection()

' Add 1 to month to determine the
' last day of the selected month later on...
iMonth = iMonth + 1
dtStartDate = CDate((CStr(iMonth) & "/01/" & CStr(iYr)))

' Now, subtract 1 day to get the
' last day of the month...
dtStartDate = DateAdd("d", -1, dtStartDate)

' return results
GetStartDate = dtStartDate
Exit_GetStartDate:
Exit Function

Err_GetStartDate:
Dim iResp%

iResp = MsgBox("Error #" & Err.Number & vbCrLf & _
Err.Description, vbRetryCancel + vbExclamation)
If iResp = vbRetry Then Resume
Resume Exit_GetStartDate
End Function

Public Function GetMonthNumFromSelection() As Integer
Select Case cboMonth.Value
Case "Jan"
GetMonthNumFromSelection = 1
Case "Feb"
GetMonthNumFromSelection = 2
Case "Mar"
GetMonthNumFromSelection = 3
Case "Apr"
GetMonthNumFromSelection = 4
Case "May"
GetMonthNumFromSelection = 5
Case "Jun"
GetMonthNumFromSelection = 6
Case "Jul"
GetMonthNumFromSelection = 7
Case "Aug"
GetMonthNumFromSelection = 8
Case "Sep"
GetMonthNumFromSelection = 9
Case "Oct"
GetMonthNumFromSelection = 10
Case "Nov"
GetMonthNumFromSelection = 11
Case "Dec"
GetMonthNumFromSelection = 12
Case Else
GetMonthNumFromSelection = 0
End Select
End Function


Use GetStartDate() in your criteria - (Ex: dtRcvd_Date >
GetStartDate())

Dec 12 '07 #2
turtle wrote:
Background:
I have a table of fields each field representing a month (Jan, Feb,
Mar...). These are not a date field but more of a bucket to hold
labor actuals. Along with the months their is another field for
year. Looking at the table you can see which month and which year the
hours belong to but since the month buckets are not actual dates it is
hard to write certain criteria's that represent dates. I have linked
to a suppliers database and that is why it is this way (not something
i created).

Problem:
What i need is to write a parameter function that would allow me to
see only the dates that are greater than a parameter value.

My not so good VB skills solution (need help finishing):
I thought that i could do a select case that would look something like
this. I would have a combo box for month (cboMonth) and combo box for
year (cboYear).

Case1: Jan+Feb+Mar+Apr...
Case2: Feb+Mar+Apr+May...
Case3: Mar+Apr+May+Jun...
Case4: Apr+May+Jun+Jul...

If CboMonth = "Jan" then
Case1 where [Year] >= cboYear
If CboMonth = "Feb" then
Case2 where year = cboYear + Case1 where [year] cboYear
If CboMonth = "Mar" then
Case3 where year =cboYear + Case1 where [year] cboYear
...

First question - how close am i on the code? Am i on the right
track?
Second Question - If i save this as a function and call it in a query
how does it work to get the parameters that are on my form? Really i
need someone to fill the gaps of how to do this. i really suck at the
VB side of Access.

Any help would be awesome.

KO
I'm not sure you really need code...if you are using a form to store
your form's month and year.

I created a form that has 2 combos; C1 and C2. C1 for year, C2 for
Month. In my table is a Date field called DateFld. I demonstrate how
you can use a specific value or use values from the form.

SELECT ID, DateFld, DateFld
FROM Table1
WHERE (((DateFld)>DateSerial(2007,1,1)) AND
((DateFld)>DateSerial(2007,[Forms]![Form1]![t1],[Forms]![Form1]![t2])));

Bomb
http://www.youtube.com/watch?v=nETVIeygqjY
Dec 13 '07 #3
On Dec 12, 3:18 pm, Technolust <queenskni...@technologist.comwrote:
On Dec 12, 10:32 am, turtle <kol...@vistacontrols.comwrote:


Background:
I have a table of fields each field representing a month (Jan, Feb,
Mar...). These are not a date field but more of a bucket to hold
labor actuals. Along with the months their is another field for
year. Looking at the table you can see which month and which year the
hours belong to but since the month buckets are not actual dates it is
hard to write certain criteria's that represent dates. I have linked
to a suppliers database and that is why it is this way (not something
i created).
Problem:
What i need is to write a parameter function that would allow me to
see only the dates that are greater than a parameter value.
My not so good VB skills solution (need help finishing):
I thought that i could do a select case that would look something like
this. I would have a combo box for month (cboMonth) and combo box for
year (cboYear).
Case1: Jan+Feb+Mar+Apr...
Case2: Feb+Mar+Apr+May...
Case3: Mar+Apr+May+Jun...
Case4: Apr+May+Jun+Jul...
If CboMonth = "Jan" then
Case1 where [Year] >= cboYear
If CboMonth = "Feb" then
Case2 where year = cboYear + Case1 where [year] cboYear
If CboMonth = "Mar" then
Case3 where year =cboYear + Case1 where [year] cboYear
...
First question - how close am i on the code? Am i on the right
track?
Second Question - If i save this as a function and call it in a query
how does it work to get the parameters that are on my form? Really i
need someone to fill the gaps of how to do this. i really suck at the
VB side of Access.
Any help would be awesome.
KO

Maybe u need something like this?...

Public Function GetStartDate() As Date
Dim iMonth%, iYr%
Dim dtStartDate As Date

On Error GoTo Err_GetStartDate

iYr = CInt(cboYear.Value)
iMonth = GetMonthNumFromSelection()

' Add 1 to month to determine the
' last day of the selected month later on...
iMonth = iMonth + 1
dtStartDate = CDate((CStr(iMonth) & "/01/" & CStr(iYr)))

' Now, subtract 1 day to get the
' last day of the month...
dtStartDate = DateAdd("d", -1, dtStartDate)

' return results
GetStartDate = dtStartDate
Exit_GetStartDate:
Exit Function

Err_GetStartDate:
Dim iResp%

iResp = MsgBox("Error #" & Err.Number & vbCrLf & _
Err.Description, vbRetryCancel + vbExclamation)
If iResp = vbRetry Then Resume
Resume Exit_GetStartDate
End Function

Public Function GetMonthNumFromSelection() As Integer
Select Case cboMonth.Value
Case "Jan"
GetMonthNumFromSelection = 1
Case "Feb"
GetMonthNumFromSelection = 2
Case "Mar"
GetMonthNumFromSelection = 3
Case "Apr"
GetMonthNumFromSelection = 4
Case "May"
GetMonthNumFromSelection = 5
Case "Jun"
GetMonthNumFromSelection = 6
Case "Jul"
GetMonthNumFromSelection = 7
Case "Aug"
GetMonthNumFromSelection = 8
Case "Sep"
GetMonthNumFromSelection = 9
Case "Oct"
GetMonthNumFromSelection = 10
Case "Nov"
GetMonthNumFromSelection = 11
Case "Dec"
GetMonthNumFromSelection = 12
Case Else
GetMonthNumFromSelection = 0
End Select
End Function

Use GetStartDate() in your criteria - (Ex: dtRcvd_Date >
GetStartDate())- Hide quoted text -

- Show quoted text -
I don't have any date fields just a year field. In what field to i
put the criteria? Sorry for my lack of understanding.
thanks,
KO
Dec 13 '07 #4
On Wed, 12 Dec 2007 10:32:04 -0800 (PST), turtle
<ko****@vistacontrols.comwrote:
>Background:
I have a table of fields each field representing a month (Jan, Feb,
Mar...). These are not a date field but more of a bucket to hold
labor actuals. Along with the months their is another field for
year. Looking at the table you can see which month and which year the
hours belong to but since the month buckets are not actual dates it is
hard to write certain criteria's that represent dates. I have linked
to a suppliers database and that is why it is this way (not something
i created).

Problem:
What i need is to write a parameter function that would allow me to
see only the dates that are greater than a parameter value.

My not so good VB skills solution (need help finishing):
I thought that i could do a select case that would look something like
this. I would have a combo box for month (cboMonth) and combo box for
year (cboYear).

Case1: Jan+Feb+Mar+Apr...
Case2: Feb+Mar+Apr+May...
Case3: Mar+Apr+May+Jun...
Case4: Apr+May+Jun+Jul...

If CboMonth = "Jan" then
Case1 where [Year] >= cboYear
If CboMonth = "Feb" then
Case2 where year = cboYear + Case1 where [year] cboYear
If CboMonth = "Mar" then
Case3 where year =cboYear + Case1 where [year] cboYear
...

First question - how close am i on the code? Am i on the right
track?
Second Question - If i save this as a function and call it in a query
how does it work to get the parameters that are on my form? Really i
need someone to fill the gaps of how to do this. i really suck at the
VB side of Access.

Any help would be awesome.

KO
One possible approach might be to create a "normalizing" query. This
is a bit convoluted, but I tried it and it seems to work.

select Jan as M, cvdate("1/1/" & [fldYear]) as D from t
union all
select Feb, cvdate("2/1/" & [fldYear]) from t
union all
select Mar, cvdate("3/1/" & [fldYear]) from t
.... etc

All of your valiues end up in M with the date in D. You can then
easily query from that, using D in the WHERE clause.

Hope this might be of some help.
Dec 13 '07 #5
On Dec 13, 11:49 am, Arch <send...@spam.netwrote:
On Wed, 12 Dec 2007 10:32:04 -0800 (PST), turtle

<kol...@vistacontrols.comwrote:
Background:
I have a table of fields each field representing a month (Jan, Feb,
Mar...). These are not a date field but more of a bucket to hold
labor actuals. Along with the months their is another field for
year. Looking at the table you can see which month and which year the
hours belong to but since the month buckets are not actual dates it is
hard to write certain criteria's that represent dates. I have linked
to a suppliers database and that is why it is this way (not something
i created).
Problem:
What i need is to write a parameter function that would allow me to
see only the dates that are greater than a parameter value.
My not so good VB skills solution (need help finishing):
I thought that i could do a select case that would look something like
this. I would have a combo box for month (cboMonth) and combo box for
year (cboYear).
Case1: Jan+Feb+Mar+Apr...
Case2: Feb+Mar+Apr+May...
Case3: Mar+Apr+May+Jun...
Case4: Apr+May+Jun+Jul...
If CboMonth = "Jan" then
Case1 where [Year] >= cboYear
If CboMonth = "Feb" then
Case2 where year = cboYear + Case1 where [year] cboYear
If CboMonth = "Mar" then
Case3 where year =cboYear + Case1 where [year] cboYear
...
First question - how close am i on the code? Am i on the right
track?
Second Question - If i save this as a function and call it in a query
how does it work to get the parameters that are on my form? Really i
need someone to fill the gaps of how to do this. i really suck at the
VB side of Access.
Any help would be awesome.
KO

One possible approach might be to create a "normalizing" query. This
is a bit convoluted, but I tried it and it seems to work.

select Jan as M, cvdate("1/1/" & [fldYear]) as D from t
union all
select Feb, cvdate("2/1/" & [fldYear]) from t
union all
select Mar, cvdate("3/1/" & [fldYear]) from t
... etc

All of your valiues end up in M with the date in D. You can then
easily query from that, using D in the WHERE clause.

Hope this might be of some help.- Hide quoted text -

- Show quoted text -
I think that might work but if i have other fields how do i include
them?
Do i just add a Select statement at the beginning or the end? When i
try it i either get a number of columns different from the two tables
or a from clause error.

thanks,
KO
Dec 13 '07 #6

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

Similar topics

6
by: Edward King | last post by:
Hi! I am trying to achieve the following: I have a number of help pages (in the format help_nn.php where nn=helpid). I want to be able to open a particular help page by calling the function...
4
by: Joneseyboy | last post by:
Hi, I'm new to this so I could really do with some help! I am using VB.net to create a small game. basically there is a Textbox, a button and a listbox. The user enters a number into the...
2
by: Chuck Martin | last post by:
I am having a most frustrating problem that references, web searches, and other resources are no help so far in solving. Basically, I'm trying to design a pop-up window to be called with a funciton...
1
by: intl04 | last post by:
I'm trying to set up a query that will include a new field ('Days until completion') whose value is derived from the DateDiff function. I think I have the syntax correct but am not sure. Days...
7
by: Mike D. | last post by:
I have a problem with a dynamic library I am developing, but it is really more of a pointer issue than anything else. Hopefully someone here can lend me some assistance or insight into resolving...
4
by: George Durzi | last post by:
I created a simple user control which contains a hyperlink to link the user to a topic in a compiled help file. I named all my help topics to have the same name as the aspx they are for. So in...
7
by: Jimakos Bilakis | last post by:
Hi guys! I'm using the C++ Builder 6 Enterprise Edition where I create some tables in Paradox and with the help of a structure i pass my data from the form (Edit boxes) to the Paradox table with...
10
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
1
by: Beamor | last post by:
function art_menu_xml_parcer($content, $showSubMenus) { $doc = new DOMDocument(); $doc->loadXML($content);//this is the line in question $parent = $doc->documentElement; $elements =...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
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
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...
0
jinu1996
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...
0
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...

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.