Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / December 2005

Tip: Looking for answers? Try searching our database.

Calculator.. type mismatch error when closing?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brook - 03 Dec 2005 21:58 GMT
good day all,

I found a calculator for an access db and copied it to my existing db, it
opens fine and everything functions fine except when I try to close the form
I get the following error:

Run-time error "13":

Type Mismatch

when I click the debug button, it goes to the code for the form and
specifically to the *** area...

Private Function ChangeProperty(strPropName As String, varPropType As
Variant, varPropValue As Variant) As Boolean
'Changes the database property passed to the datatype and value passed.
'If the property does not exist an error is generated and the property is
created.

 Dim dbMdb As Database, prp As Property
 Const conPropNotFoundError = 3270
 Set dbMdb = CurrentDb
 On Error GoTo Change_Err
 dbMdb.Properties(strPropName) = varPropValue
 ChangeProperty = True
Change_Bye:
 Exit Function
Change_Err:
 If Err = conPropNotFoundError Then  'prop not found
*****    Set prp = dbMdb.CreateProperty(strPropName, varPropType,
varPropValue)
   dbMdb.Properties.Append prp
   Resume Next
 Else
   'unknown error
   ChangeProperty = False
   Resume Change_Bye
 End If
End Function

Does anyone have any ideas suggestions on what might be causing this?

Thanks,

BRook
Douglas J. Steele - 03 Dec 2005 22:58 GMT
Let me guess. You're using Access 2000 or 2002. You've added a reference to
DAO (or else Dim dbMdb As Database would have caused an error), but you
didn't remove the reference to ADO when you did that.

If you have both references, you'll find that you'll need to "disambiguate"
certain declarations, because objects with the same names exist in the 2
models. For example, to ensure that you get a DAO property, you'll need to
use Dim prp as DAO.Property (to guarantee an ADO recordset, you'd use Dim
prp As ADODB.Property)

The list of objects with the same names in the 2 models is Connection,
Error, Errors, Field, Fields, Parameter, Parameters, Property, Properties
and Recordset

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> good day all,
>
[quoted text clipped - 42 lines]
>
> BRook
Brook - 03 Dec 2005 23:22 GMT
Douglas,

 you are correct... How do I remove the reference to ADO? Will removing the
ADO reference interfere with my remaining DB?

 I really just exported the calculator from the downloaded DB to my DB.

Thanks,

Brook

> Let me guess. You're using Access 2000 or 2002. You've added a reference to
> DAO (or else Dim dbMdb As Database would have caused an error), but you
[quoted text clipped - 56 lines]
> >
> > BRook
Douglas J. Steele - 03 Dec 2005 23:46 GMT
Whether removing the ADO reference will cause problems depends on whether or
not you're using ADO anywhere else in your database. Open the References
dialog and remove the reference to the Microsoft ActiveX Data Objects 2.x
Library then do a compile on your database (under the Debug menu). If it
compiles cleanly, then odds are you're not using ADO, and you can safely
keep the reference out. Otherwise, leave it in and ensure you disambiguate
all declarations of the objects I listed below.

There's nothing wrong with having both ADO and DAO in the same database. I
do it all the time when I've got applications that talk to both Jet (.MDB)
and SQL Server. (DAO is designed specifically for Jet databases, so is
almost always more efficient.)

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Douglas,
>
[quoted text clipped - 73 lines]
>> >
>> > BRook
Brook - 03 Dec 2005 23:54 GMT
to be on the safe side, how would I configure my DB to accept both references
like you have done?

Brook

> Whether removing the ADO reference will cause problems depends on whether or
> not you're using ADO anywhere else in your database. Open the References
[quoted text clipped - 86 lines]
> >> >
> >> > BRook
Douglas J. Steele - 04 Dec 2005 01:55 GMT
As I said, if you have both references set, you need to disambiguate all
declarations for Connection, Error, Errors, Field and Fields objects.

For example, to ensure that you get a DAO property, you'll need to use Dim
prp as DAO.Property (to guarantee an ADO recordset, you'd use Dim prp As
ADODB.Property)

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> to be on the safe side, how would I configure my DB to accept both
> references
[quoted text clipped - 108 lines]
>> >> >
>> >> > BRook
Brook - 04 Dec 2005 03:14 GMT
Thank you very much,

I was able to get everything working properly...

Brook

> As I said, if you have both references set, you need to disambiguate all
> declarations for Connection, Error, Errors, Field and Fields objects.
[quoted text clipped - 115 lines]
> >> >> >
> >> >> > BRook
Douglas J. Steele - 04 Dec 2005 12:06 GMT
You're welcome.

Just thought I'd point out that I did an incomplete copy-and-paste job when
listing the objects you need to disambiguate. The complete list of objects
which exist in both the DAO and ADO models is Connection, Error, Errors,
Field, Fields, Parameter, Parameters, Property, Properties and Recordset.
(it was correct when I first listed it in this thread!)

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Thank you very much,
>
[quoted text clipped - 137 lines]
>> >> >> >
>> >> >> > BRook
Brook - 04 Dec 2005 13:22 GMT
Douglas,

I couldn't figure out how to "disambiguate" so I just created a new "close"
form button as a work around.

Here is the code for the original close button that was giving me the error:

Private Sub cmdClose_Click()
 Dim boolRet As Boolean
 boolRet = ChangeProperty("calcDisplay", dbDouble, Val(txtDisplay.Caption))
 boolRet = ChangeProperty("calcMem", dbDouble, Val(lblMem.Caption))
 boolRet = ChangeProperty("calcTempStore", dbDouble,
Val(lblTempStore.Caption))
 DoCmd.Close acForm, Me.Name
End Sub

If you have any suggestions, I'm open.

Also, do you know of any good articles on how to "disambiguate"?

Thanks,

Brook

> You're welcome.
>
[quoted text clipped - 145 lines]
> >> >> >> >
> >> >> >> > BRook
Douglas J. Steele - 04 Dec 2005 14:27 GMT
Disambiguation simply means to explicitly include the name of the class when
you declare the object or when you refer to a method or property of an
object.

Use Dim rst As DAO.Recordset or Dim rst As ADODB.Recordset as opposed to Dim
rst As Recordset.

The "refer to a method or property of an object" means that rather than
using Left(MyString, 4), you could use VBA.Left(MyString, 4), since the Left
function comes from the VBA library.

That's all. So for this particular problem, you need to change the one line
of code in ChangeProperty from

Dim dbMdb As Database, prp As Property

to

Dim dbMdb As DAO.Database, prp As DAO.Property

(Okay, it's not 100% necessary to use DAO.Database, since there isn't a
Database object in any other of the "common" references. However, there's
nothing wrong with it either.)

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Douglas,
>
[quoted text clipped - 22 lines]
>
> Brook
Brook - 04 Dec 2005 21:29 GMT
Douglas...

 Thanks for explaining this further... Now I understand what you meant by
your first post...

 Everything works great...

Brook

> Disambiguation simply means to explicitly include the name of the class when
> you declare the object or when you refer to a method or property of an
[quoted text clipped - 46 lines]
> >
> > Brook
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.