Is VBA code written for Access97 compatible with Access 2002

T

TPP

The code listed below works fine with Access 97, but not when used in Access
2002. Are there compatibility issues with using the "old but good" code in
the newer version of Access? The VISITES table referenced in the code remains
unchanged between the Access 97 and 2002 version of my database. Any
suggestions?

Function Set_Rendement()
Dim DB As Database, T As Recordset
Dim S As String, OldEnv As Variant, OldVeh As Variant
Dim OldC1 As Variant, OldC2 As Variant, TotC1 As Variant, TotC2 As Variant
Dim C1 As Variant, C2 As Variant

Set DB = DBEngine.Workspaces(0).Databases(0)
S = "Select
VISITES.IDEnv,VISITES.Date,VISITES.Operation,VISITES.IDVeh,VISITES.Compt1,VISITES.Compt2"
S = S + ",VISITES.D1,VISITES.D2,VISITES.T1,VISITES.T2 From VISITES"
S = S + " Order by VISITES.IDEnv,VISITES.Date,VISITES.Operation;"
Set T = DB.OpenRecordset(S, DB_OPEN_DYNASET)
T.MoveFirst
OldEnv = -1
Do Until T.EOF
If T("IDEnv") <> OldEnv Then
OldEnv = T("IDEnv")
OldVeh = T("IDVeh")
C1 = 0
C2 = 0
TotC1 = 0
TotC2 = 0
Else
If T("IDVeh") <> OldVeh Then
C1 = 0
C2 = 0
OldVeh = T("IDVeh")
Else
C1 = T("Compt1") - OldC1
C2 = T("Compt2") - OldC2
End If
TotC1 = TotC1 + C1
TotC2 = TotC2 + C2
End If
OldC1 = T("Compt1")
OldC2 = T("Compt2")
T.Edit
T("D1") = C1
T("D2") = C2
T("T1") = TotC1
T("T2") = TotC2
T.Update
T.MoveNext
Loop
T.Close
End Function
 
D

Dirk Goldgar

TPP said:
The code listed below works fine with Access 97, but not when used in
Access 2002. Are there compatibility issues with using the "old but
good" code in the newer version of Access? The VISITES table
referenced in the code remains unchanged between the Access 97 and
2002 version of my database. Any suggestions?

Function Set_Rendement()
Dim DB As Database, T As Recordset
Dim S As String, OldEnv As Variant, OldVeh As Variant
Dim OldC1 As Variant, OldC2 As Variant, TotC1 As Variant, TotC2 As
Variant Dim C1 As Variant, C2 As Variant

Set DB = DBEngine.Workspaces(0).Databases(0)
S = "Select
VISITES.IDEnv,VISITES.Date,VISITES.Operation,VISITES.IDVeh,VISITES.Compt
1,VISITES.Compt2"
S = S + ",VISITES.D1,VISITES.D2,VISITES.T1,VISITES.T2 From VISITES"
S = S + " Order by VISITES.IDEnv,VISITES.Date,VISITES.Operation;"
Set T = DB.OpenRecordset(S, DB_OPEN_DYNASET)
T.MoveFirst
OldEnv = -1
Do Until T.EOF
If T("IDEnv") <> OldEnv Then
OldEnv = T("IDEnv")
OldVeh = T("IDVeh")
C1 = 0
C2 = 0
TotC1 = 0
TotC2 = 0
Else
If T("IDVeh") <> OldVeh Then
C1 = 0
C2 = 0
OldVeh = T("IDVeh")
Else
C1 = T("Compt1") - OldC1
C2 = T("Compt2") - OldC2
End If
TotC1 = TotC1 + C1
TotC2 = TotC2 + C2
End If
OldC1 = T("Compt1")
OldC2 = T("Compt2")
T.Edit
T("D1") = C1
T("D2") = C2
T("T1") = TotC1
T("T2") = TotC2
T.Update
T.MoveNext
Loop
T.Close
End Function

The code is okay, but Access 2002 doesn't set up new databases with a
reference to DAO by default -- it sets one to ADO instead. Click
Tools -> References..., remove the check mark next to "Microsoft ActiveX
Data Objects 2.x Library", then look down the list for "Microsoft DAO
3.6 Object Library" and put a check mark next to it.

Also, the constant DB_OPEN_DYNASET is outdated, but should still work.
You could replace it with dbOpenDynaset, to be more current.
 
M

Marshall Barton

TPP said:
The code listed below works fine with Access 97, but not when used in Access
2002. Are there compatibility issues with using the "old but good" code in
the newer version of Access? The VISITES table referenced in the code remains
unchanged between the Access 97 and 2002 version of my database.
[snip the good old code]


The biggest issue between A97 and A2K, AXP is the References
and the most common reference problem is that ADO is the
default data access library. You probably need to uncheck
ActiveX Data Objects and select DAO.
 

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