Solved

Type mismatch for year() and month()

Posted on 2003-12-06
16
446 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
[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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

737 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