?
Solved

User Defined Function now working in query design grid in ACCESS 2003

Posted on 2007-12-03
6
Medium Priority
?
1,085 Views
Last Modified: 2008-02-01
I need to supply the function with the name of the month and have it give me back the integer.  Simply, I created the function, which does work.  However, in the code snippet, the first line is my call using it in the query grid of ACCESS 2003.  I simply cannot figure out how to tell it what the month is.  "445"Month" is another column with varying month names, so I do not understand where my flaw is.
MonthNo: WhatMonthIsIt("&tblSalesDaily445_and_Calendar.445Month&")
 
Public Function WhatMonthIsIt(ByRef strMonthName As String) As Integer
 
If strMonthName = "Jan" Or strMonthName = "January" Then WhatMonthIsIt = 1
If strMonthName = "Feb" Or strMonthName = "February" Then WhatMonthIsIt = 2
If strMonthName = "Mar" Or strMonthName = "March" Then WhatMonthIsIt = 3
If strMonthName = "Apr" Or strMonthName = "April" Then WhatMonthIsIt = 4
If strMonthName = "May" Or strMonthName = "May1" Then WhatMonthIsIt = 5
If strMonthName = "Jun" Or strMonthName = "June" Then WhatMonthIsIt = 6
If strMonthName = "Jul" Or strMonthName = "July" Then WhatMonthIsIt = 7
If strMonthName = "Aug" Or strMonthName = "August" Then WhatMonthIsIt = 8
If strMonthName = "Sep" Or strMonthName = "September" Then WhatMonthIsIt = 9
If strMonthName = "Oct" Or strMonthName = "October" Then WhatMonthIsIt = 10
If strMonthName = "Nov" Or strMonthName = "November" Then WhatMonthIsIt = 11
If strMonthName = "Dec" Or strMonthName = "December" Then WhatMonthIsIt = 12
 
End Function

Open in new window

0
Comment
Question by:ssmith94015
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 20398886
>WhatMonthIsIt("&tblSalesDaily445_and_Calendar.445Month&")
The double-quotes mean you are passing a string named &tblSalesDaily445_and_Calendar.445Month&"), which doesn't translate to any month in your WhatMonthIsIt function.

Exactly how are you determining what month to feed the function?
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 20398912
btw this is much easier to read

Public Function WhatMonthIsIt(sMonth as string) as Integer

Select Case Left(UCase(sMonth), 3)
   Case "JAN"
      WhatMonthIsIt = 1
   Case "FEB"
      WhatMonthIsIt = 2
   Case "MAR"
      WhatMonthIsIt = 3
   Case "You get the idea...."

   Case "DEC"
      WhatMonthIsIt = 12
   Case Else
      'You passed an unreadable month into sMonth.  Handle it here.
End Select

End Sub
0
 

Author Comment

by:ssmith94015
ID: 20398950
Hello Jim, I tried the Select Case statement first, but could not get it to work.  The If statement sequence at least (in the immediate window and when I type in the month name in the funciton in query grid) does return the appropriate value.  In the query, there is another column entitled 445Month that contains the string short names for the months, ie., Jan, Feb, Mar, etc.  So, I want to pass the values from this column to my function, but I know that my function needs quotes for a string and I think that is where I am getting stuck.  But I have tried various combinations of quiotes and getting no where.  I tried using the full qualified name of the column (table.columnname) and just the column name in the function, but neither worked as well.
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 total points
ID: 20398988
Give this a whirl..

MonthNo: WhatMonthIsIt([tblSalesDaily445_and_Calendar].[445Month])
0
 

Author Comment

by:ssmith94015
ID: 20399007
WORKED!!!!!
0
 

Author Comment

by:ssmith94015
ID: 20399018
thank you very much!
0

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question