【问题标题】:VBA code from 32 bit to 64 bit - Ms Access从 32 位到 64 位的 VBA 代码 - Ms Access
【发布时间】:2012-09-16 11:02:28
【问题描述】:

我在运行 32 位 Microsoft Office 的 64 位机器(Windows 7)上构建了一个应用程序。客户端机器是64位windows和64位office。

我最初遇到了 comdlg32.dll 的问题,但包含了 PtrSafe 关键字。下一个问题是我安装到客户端机器中的 IPCONFIG.dll 丢失。

我现在可以编译了,但我正在尝试使用文件保存对话框(Ken Getz 编写的代码)。它似乎跳过了打开实际对话框并直接运行到运行时错误 2522(需要文件名)。任何帮助表示赞赏。这是我正在使用的代码(引用 Ken Getz 的函数):

Function exportData_Click()


Dim strFilter As String
Dim strSaveFileName As String
Dim The_Year As Variant

Dim ctlCurrentControl As Control
Dim queryName As String



'Get the name of the control button clicked (corresponds to query name to be run)
Set ctlCurrentControl = Screen.ActiveControl
queryName = ctlCurrentControl.Name



'Get combobox value and assign relavent values to The_Year
The_Year = Forms![Extract Data]!Extract_Year.value


'Change the year from a variant to what we need in the SQL

If The_Year Like "20*" Then
    The_Year = CInt(The_Year)
    'MsgBox The_Year & "Data Type = " & VarType(The_Year)
Else: The_Year = "*"
'MsgBox The_Year & "Data Type = " & VarType(The_Year)
End If

'Set queryYear variable
setYear (The_Year)


'Check the variable is correct
'MsgBox getYear()

'Open the Save as Dialog to choose location of query save

strFilter = ahtAddFilterItem("Excel Files (*.xlsx)", "*.xlsx")

strSaveFileName = ahtCommonFileOpenSave( _
                                openFile:=False, _
                                Filter:=strFilter, _
                Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY)

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, queryName, strSaveFileName

End Function

调试指向这一行:

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, queryName, strSaveFileName

【问题讨论】:

    标签: ms-access vba ms-access-2010 32bit-64bit


    【解决方案1】:

    我发现此代码适用于 MS Access 64:

    Function GetFile(strStartIn As String, strFilter As String) As String
    Dim f As Object
    
       Set f = Application.FileDialog(3)
       f.AllowMultiSelect = False
       f.InitialFileName = strStartIn & strFilter
       f.Show
    
       GetFile = f.SelectedItems(1)
    End Function
    

    它不像 Ken Getz 的代码那样简洁,但应该适合选择要保存或打开的文件。您可以参考 Microsoft Office 库来使用内置常量,例如:

    msoFileDialogOpen (1) 
    msoFileDialogSaveAs (2)
    msoFileDialogFilePicker (3) 
    msoFileDialogFolderPicker (4) 
    

    (http://msdn.microsoft.com/en-us/library/office/aa190813(v=office.10).aspx#ofobjFileDialogFilters)

    【讨论】:

    • 谢谢 remou。它不会与 Return = 语句一起编译。我已经注释掉了,对话框正在出现。但是,saveAs 仍然没有保存任何内容。
    • 所有排序。我刚刚使用了 String (strSaveFileName) = f.SelectedItems(1) 非常感谢 remou!
    【解决方案2】:

    对我的应用程序效果很好的另一种方法是检查 VBA 的版本:

    #if Vba7 then 
    '  Code is running in the new VBA7 editor 
         #if Win64 then 
         '  Code is running in 64-bit version of Microsoft Office 
         #else 
         '  Code is running in 32-bit version of Microsoft Office 
         #end if 
    #else 
    ' Code is running in VBA version 6 or earlier 
    #end if 
    
    #If Vba7 Then 
    Declare PtrSafe Sub... 
    #Else 
    Declare Sub... 
    #EndIf 
    

    http://msdn.microsoft.com/en-us/library/office/gg264421.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-13
      • 2012-02-10
      • 2017-07-22
      • 1970-01-01
      • 2017-02-18
      • 1970-01-01
      • 2010-09-12
      相关资源
      最近更新 更多