Option Explicit

  • Thread starter Frank Situmorang
  • Start date
F

Frank Situmorang

Hello,

Is it true that on every fisrt line of our module should begin with the
"Option Explicit" in order to pruduce the correct output?

I have ever experience that calender field using the popup calender was
error with the message mismatched format" and it's ok again when I put this
Option Explicit.

Thanks for your explanantion.
 
A

Allen Browne

It is good practice to use Option Explicit in every module. Without it, if
you misspell a variable, Access just creates a new one with that name, so it
is a real nightmare to figure out why the program is not working correctly.

The mismatched type error message indicates that there has been an attempt
to assign an inappropriate value. For example, perhaps you tried to assign a
zero-length string to something that should be a date, like this:
Me.[MyDate] = "" ' <= Error!

Likewise, if you declare a Number or a String and try to assign a Null to it
it fails:
Dim str1 As String
str1 = Me.[City] ' <= Fails if City is Null
If the value could be null, use a Variant instead:
Dim var1 As Variant
var1 = Me.[City]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top