Tempvars and access 2003

别说谁变了你拦得住时间么 提交于 2019-12-11 16:17:56

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3426693/tempvars-and-access-2003

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!