Tempvars and access 2003

2019-08-22 04:35发布

I have a database that is used in a mixed 2003, 2007 environment. I have some minor functionality that uses 2007's new TempVars feature. If it is a 2003 user, it isn't a problem for them to not have those features.

How do I write my code so that it will compile and run on Access 2003. I have tried on error resume next but this doesn't work for compile time errors.

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-22 05:16

Here is a nice summary about using VBA built-in compiler constants.
#If VBA7 Then could help you to differentiate Office 2010 only code. Unfortunately it does not apply to Office 2007.

查看更多
Bombasti
3楼-- · 2019-08-22 05:24

If your application will be used with Access 2003, seems to me you should exclude features 2003 doesn't support.

However, if you must have Tempvars, see whether a conditional compiler constant approach would make it work for you.

Option Compare Database
Option Explicit
#Const Aversion = "2007" 'conditional compiler constant '

Public Sub HelloWorld()
    Dim strWho As String
    strWho = "World"

    #If Aversion = "2007" Then
        '* your 2007 feature code here *'
        strWho = UCase(strWho)
    #End If
    'Aversion 2003 -> Hello World '
    'Aversion 2007 -> Hello WORLD '
    Debug.Print "Hello " & strWho
End Sub

Check Access' Help for more information about #Const and #If.

I haven't tested this, but I think it could work. You might need two copies of your database: YourDb2003.mdb; and YourDb2007.mdb. In YourDb2003.mdb use "2003" as the compiler constant, and "2007" in YourDb2007.mdb.

查看更多
登录 后发表回答