Solved

Type mismatch for year() and month()

Posted on 2003-12-06
16
444 Views
Last Modified: 2008-03-17
Hi,
   On my access application, I am writing an Event procedure in VBA to get no. of working days. But i have found some type mismatch error when i use year(now()) or month(now()). With this i have noticed that Year() , month() and Day()  function is not working only for that editor.  what could be wrong here?

I am expecting an early response.

regards,
Nabeel.
0
Comment
Question by:nabeelkp
  • 8
  • 4
  • 2
  • +1
16 Comments
 
LVL 10

Expert Comment

by:jobrienct
ID: 9887636
post your code pls.

John
0
 
LVL 3

Expert Comment

by:klyon
ID: 9887650
nabeelkp,

You will get these kinds of crazy errors, if you have problems with your References.  When in the VBA Editor, go to Tools -> References, and check to see if you have any References that say "MISSING:" in front of them.

Kevin
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 9887655
Hi nabeelkp

They all return an integer, what have you declared your variables as?

Alan :)
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 10

Expert Comment

by:jobrienct
ID: 9887656
If you do, uncheck the references and then recheck them and see if that helps.

John
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 9887659
Dim iYr as integer
Dim iMth as integer
Dim iDay as Integer

iYr = Year(Now)
Imth = Month(Now)
iDay = Day(Now)

debug.Print iYr, iMth, iDay

0
 

Author Comment

by:nabeelkp
ID: 9887729
Hi,
  There is no missing links in "reference" , funny thing is that Day() function is working , but year() and month() it even didn't recognize as a function only in this project.
If i create a test database and try this functions , it works just fine.
I want to fix this one on my running project.


0
 
LVL 10

Expert Comment

by:jobrienct
ID: 9887736
create a new database and import all your objects - sounds like corruption perhaps. If that works then just rename the original database and then name the new database with the original filename.

John
0
 
LVL 3

Expert Comment

by:klyon
ID: 9887744
jobrienct is onto something...  A good, old-fashioned "Compact and Repair" might straighten things out too.  But, before you do it, be sure to back up your database, just in case.
0
 
LVL 10

Expert Comment

by:jobrienct
ID: 9887758
I find its easier to just move it all out of the offending database usually, start clean. Sometimes it saves a step. If thine object offend thee... cut it off.

John
0
 

Author Comment

by:nabeelkp
ID: 9888181
Hi,
  I have created a new MS database and import all objects and it still shows the same. For the same project, some of forms VBA give me  Year() and month() working.

Nabeel.
0
 
LVL 10

Expert Comment

by:jobrienct
ID: 9888612
ok so corruption is not the issue. so can you please post your vba code thats not working ?

John
0
 

Author Comment

by:nabeelkp
ID: 9891084
Hi,
   I am sure that my code is correct as it is working in a separate form i have tried by creating a dummy access db.  
   EndDate = Day(DateSerial(Year(Now()), Month(Now()) + 1, 0))
This will actually return no. of days in a month. But it shows me type mismatch error only for that particular form vba editor  , because year() and Month doesn't recognize as a function for that current editor.

Nabeel.
0
 
LVL 10

Accepted Solution

by:
jobrienct earned 100 total points
ID: 9891153
so you have the exact same code in another form and its working... odd, something has to be amiss with the form object, but if you imported this form into a new db, then the import actually should have brought over only the uncompiled code of the form and so i cant imagine it was corrupted in the new db.

is there anything on the form, or in a global module,  that might create a naming conflict - no fields, form controls named with internal keywords?

are you able to post the database up to a server where we might get a look at it?

John
0
 
LVL 10

Expert Comment

by:jobrienct
ID: 9891156
My next suggestion would be to recreate the form, adding that code as soon as possible, and then testing that  its working after each control you add until something you put on the form screws it up.

John
0
 

Author Comment

by:nabeelkp
ID: 9891212
Hi John,
   Thank you for your help,  I have a query fields named as month and year which makes conflict with date functions. I renamed the query fields , now my problem is solved.

regards,
Nabeel.
0
 
LVL 10

Expert Comment

by:jobrienct
ID: 9891271
glad we could help you out,

Next window please ;-)

John



0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

679 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