Solved

Type mismatch for year() and month()

Posted on 2003-12-06
16
437 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now