?
Solved

Type mismatch for year() and month()

Posted on 2003-12-06
16
Medium Priority
?
450 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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 400 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

770 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