Type mismatch

A

Alp Bekisoglu

Could someone please help on this:
Why do I get a "Type mismatch" comment the minute I open a new database with
all objects imported (definitions only for tables) from a working copy?
The code should make it display a messagebox and then display the initial
form. But instead the above message is displayed and the menu form opens
with almost everything non-functional (no forms or reports, even other menu
pages are shown).

Thanks in advance.

Alp
 
D

Douglas J. Steele

Without seeing the code in question, it's pretty much impossible for anyone
to help.

Copy the VBA code that's failing, indicating (if possible) what line causes
the error.
 
A

Alp Bekisoglu

Hi Doug,

Here's the code behind:

Private Sub Form_Open(Cancel As Integer)

Dim dbs As Database
Dim rst As Recordset

On Error GoTo Form_Open_Err

DoCmd.SelectObject acForm, "Menu", True
DoCmd.Minimize

DoCmd.Hourglass False
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("main") 'this is the master table that
program checks if there are any records
If rst.RecordCount = 0 Then
rst.AddNew

MsgBox "...here's a greeting message to the user that spans over a few
rows......"
DoCmd.OpenForm "Main", , , , , acDialog '<<< this is the main form
that is supposed to be opened when there are no records
DoCmd.OpenForm "Main_ya_table1", , , , , acDialog

End If
rst.Close
dbs.Close

Me.Filter = "[MenuNo] = 0 AND [Argument] = 'Default' "
Me.FilterOn = True

Form_Open_Exit:
Exit Sub

Form_Open_Err:
MsgBox Err.description
Resume Form_Open_Exit

End Sub

Rest of the code is very similar to the typical wizard generated switchboard
menu code, the fill function, etc.

Hope this can give a clue. Let me know if you'd rather have a look at the
complete code behind the main menu form.

Thanks,

Alp
 
D

Douglas J. Steele

What version of Access? Database is a DAO object, and Access 2000 and 2002
use ADO by default.

With any code module open, select Tools | References from the menu bar,
scroll through the list of available references until you find the one for
Microsoft DAO 3.6 Object Library, and select it. If you're not going to be
using ADO, uncheck the reference to Microsoft ActiveX Data Objects 2.x
Library

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 recordset, you'll need to
use Dim rst as DAO.Recordset (to guarantee an ADO recordset, you'd use Dim
rst As ADODB.Recordset)

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



--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Alp Bekisoglu said:
Hi Doug,

Here's the code behind:

Private Sub Form_Open(Cancel As Integer)

Dim dbs As Database
Dim rst As Recordset

On Error GoTo Form_Open_Err

DoCmd.SelectObject acForm, "Menu", True
DoCmd.Minimize

DoCmd.Hourglass False
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("main") 'this is the master table that
program checks if there are any records
If rst.RecordCount = 0 Then
rst.AddNew

MsgBox "...here's a greeting message to the user that spans over a few
rows......"
DoCmd.OpenForm "Main", , , , , acDialog '<<< this is the main form
that is supposed to be opened when there are no records
DoCmd.OpenForm "Main_ya_table1", , , , , acDialog

End If
rst.Close
dbs.Close

Me.Filter = "[MenuNo] = 0 AND [Argument] = 'Default' "
Me.FilterOn = True

Form_Open_Exit:
Exit Sub

Form_Open_Err:
MsgBox Err.description
Resume Form_Open_Exit

End Sub

Rest of the code is very similar to the typical wizard generated switchboard
menu code, the fill function, etc.

Hope this can give a clue. Let me know if you'd rather have a look at the
complete code behind the main menu form.

Thanks,

Alp

Douglas J. Steele said:
Without seeing the code in question, it's pretty much impossible for anyone
to help.

Copy the VBA code that's failing, indicating (if possible) what line causes
the error.
 
A

Alp Bekisoglu

Thanks for your reply. I am runing 2002 and the database is created as 2000
file format. My references are:
VBA
Access 10.0 Obj.Lib. (it shows 9 when opened in 2000)
OLE Automation
MS DAO 3.6 Obj.Lib.
MS ActiveX Data Objects 2.1 Lib
in both. The one that runs without a problem has data entered for testing
the application. The new one is created to test how it will behave on
installation. The only difference was in the lining up uf the references,
ActiveX was listed before DAO in the new one.

And.... while trying out the lineup, voila! I have just promoted DAO above
AX, Now the problem is gone! I just did not know the sequence of the
references were so important. One more thing learned...

Thanks a million Douglas for your time, guidance and in turn, making me
re-look at the references' lineup.





Douglas J. Steele said:
What version of Access? Database is a DAO object, and Access 2000 and 2002
use ADO by default.

With any code module open, select Tools | References from the menu bar,
scroll through the list of available references until you find the one for
Microsoft DAO 3.6 Object Library, and select it. If you're not going to be
using ADO, uncheck the reference to Microsoft ActiveX Data Objects 2.x
Library

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 recordset, you'll need to
use Dim rst as DAO.Recordset (to guarantee an ADO recordset, you'd use Dim
rst As ADODB.Recordset)

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



--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Alp Bekisoglu said:
Hi Doug,

Here's the code behind:

Private Sub Form_Open(Cancel As Integer)

Dim dbs As Database
Dim rst As Recordset

On Error GoTo Form_Open_Err

DoCmd.SelectObject acForm, "Menu", True
DoCmd.Minimize

DoCmd.Hourglass False
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("main") 'this is the master table that
program checks if there are any records
If rst.RecordCount = 0 Then
rst.AddNew

MsgBox "...here's a greeting message to the user that spans over a few
rows......"
DoCmd.OpenForm "Main", , , , , acDialog '<<< this is the main form
that is supposed to be opened when there are no records
DoCmd.OpenForm "Main_ya_table1", , , , , acDialog

End If
rst.Close
dbs.Close

Me.Filter = "[MenuNo] = 0 AND [Argument] = 'Default' "
Me.FilterOn = True

Form_Open_Exit:
Exit Sub

Form_Open_Err:
MsgBox Err.description
Resume Form_Open_Exit

End Sub

Rest of the code is very similar to the typical wizard generated switchboard
menu code, the fill function, etc.

Hope this can give a clue. Let me know if you'd rather have a look at the
complete code behind the main menu form.

Thanks,

Alp

Douglas J. Steele said:
Without seeing the code in question, it's pretty much impossible for anyone
to help.

Copy the VBA code that's failing, indicating (if possible) what line causes
the error.
 
A

Alp Bekisoglu

Further to my reply, wich I unfortunately forgot to sign, should I take it
as I should not have DAO and ActiveX references together?

Thanks,

Alp
 
D

Douglas J. Steele

There's nothing wrong with having references set to both DAO and ADO,
provided you're using both. If you're only using DAO, you should remove the
reference to ADO. You should never have unnecessary references in your
application. No good comes out of having extraneous references, and it can
lead to problems.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Alp Bekisoglu said:
Further to my reply, wich I unfortunately forgot to sign, should I take it
as I should not have DAO and ActiveX references together?

Thanks,

Alp
 

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

Similar Threads

Type mismatch 1
type mismatch 1
type mismatch error 2
type mismatch in expression 3
getting type mismatch 3
PivotTable: Type Mismatch 0
data type mismatch 4
I get message: type mismatch 2

Top