รบกวนด้วยครับ
กระทู้เก่าบอร์ด อ.Yeadram

 1,746   5
URL.หัวข้อ / URL
รบกวนด้วยครับ

ผมได้นำไฟล์ที่ทำบน Access 2003 ไปใช้กับ 2010 พอรันขึ้นมามันฟ้องดังภาพนี้ครับไม่ทราบว่าจะต้องแก้ไขอย่างไรครับผม รบกวนท่านอาจารย์ทุกท่านด้วยครับ

5 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R18059
Compatibility Between the 32-bit and 64-bit Versions of Office 2010

- ในกรณีหากใช้งาน MS Windows 64 บิต กับโปรแกรม MS Access 64 บิต หากมีการประกาศการใช้งาน API ซึ่งปกติหากเขียนแบบ 32 บิต จะเขียนดังนี้:
---------------------------------------------------------------------------
Declare Function MyMathFunc Lib "User32" (ByVal N As LongLong) As LongLong
---------------------------------------------------------------------------
- แต่หากต้องการนำไปใช้ใน MS Access แบบ 64 บิต จำเป็นต้องเพิ่มคำสั่ง PtrSafe เพื่อให้ VBA7 รู้ว่าต้องการใช้งานไฟล์ DLL แบบ 32 บิต กับระบบ 64 บิต โดยเขียนดังนี้:
-----------------------------------------------------------------------------------
Declare PtrSafe Function MyMathFunc Lib "User32" (ByVal N As LongLong) As LongLong
-----------------------------------------------------------------------------------

- หากมีการประกาศ API เพื่อเรียกใช้งานในฟังก์ชั่น เราสามารถเขียนคำสั่งในการตรวจสอบ MS Windows ที่ใช้งานอยู่ว่าเป็น 32 บิต หรือ 64 บิต และตรวจสอบเวอร์ชั่น VBA ที่เป็น VBA เวอร์ชั่น 7 สำหรับ MS Offiec 2010 ขึ้นไป ดังตัวอย่างต่อไปนี้:

#if Win64 then
    Declare PtrSafe Function MyMathFunc Lib "User32" (ByVal N As LongLong) As LongLong
#else
    Declare Function MyMathFunc Lib "User32" (ByVal N As Long) As Long
#end if

#if VBA7 then
    Declare PtrSafe Sub MessageBeep Lib "User32" (ByVal N AS Long)
#else
    Declare Sub MessageBeep Lib "User32" (ByVal N AS Long)
#end if
2 @R18060
Qualifier     PtrSafe    Indicates that the Declare statement is compatible with 64-bits. This
                         attribute is mandatory on 64-bit systems.

Data Type     LongPtr    A variable data type which is a 4-bytes data type on 32-bit versions
                         and an 8-byte data type on 64-bit versions of Office 2010. This is the
                         recommended way of declaring a pointer or a handle for new code but
                         also for legacy code if it has to run in the 64-bit version of Office
                         2010. It is only supported in the VBA 7 runtime on 32-bit and 64-bit.
                         Note that you can assign numeric values to it but not numeric types.

Data Type     LongLong   This is an 8-byte data type which is available only in 64-bit versions
                         of Office 2010. You can assign numeric values but not numeric types (to
                         avoid truncation).

Conversion
Operator      CLngPtr    Converts a simple expression to a LongPtr data type.

Conversion
Operator      CLngLng    Converts a simple expression to a LongLong data type.

Function      VarPtr     Variant converter. Returns a LongPtr on 64-bit versions, and a Long on
                         32-bit versions (4 bytes).

Function      ObjPtr     Object converter. Returns a LongPtr on 64-bit versions, and a Long on
                         32-bit versions (4 bytes).

Function      StrPtr     String converter. Returns a LongPtr on 64-bit versions, and a Long on
                         32-bit versions (4 bytes).
3 @R18061
ขอขอบคุณ TTT อย่างมากครับผม
4 @R18062
คุณ TTT ครับ ผมขอรบกวนอีกเรื่องนึงครับผม
คือตอนนี้ผมรันตัวโปรแกรมได้แล้วครับ แต่ว่าผมเปิดตัว Dialog Explorer เพื่อที่จะ Browse หาไฟล์ไม่ได้ครับผม รบกวนคุณ TTT ช่วยดูโค๊ดที่ผมส่งมานี้ว่าผิดตรงไหนหรือต้องทำอย่างไรครับผม
Option Compare Database
Option Explicit
'************** Code Start **************

'This code was originally written by Terry Kreft.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'Code courtesy of
'Terry Kreft
Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Private Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" Alias _
            "SHGetPathFromIDListA" (ByVal pIDL As Long, _
            ByVal pszPath As String) As Long
Private Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" Alias _
            "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
            As Long
Private Const BIF_RETURNONLYFSDIRS = &H1

'** API **
'*********
'[Open File]Dialog Box API
Private Declare PtrSafe Function GetOpenFileName _
        Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
        (pOpenfilename As OPENFILENAME) As Long

'***********
'** CONST **
'***********

'***********
'** CONST **
'***********
'OPENFILENAME flags
Public Const OFN_READONLY = &H1            '[Read Only]Check On
Public Const OFN_OVERWRITEPROMPT = &H2     'Ask Overwrite
Public Const OFN_HIDEREADONLY = &H4        '[Read Only]Hide Checkbox
Public Const OFN_SHOWHELP = &H10           '[Help]Visible
Public Const OFN_ALLOWMULTISELECT = &H200 'Select Multi
Public Const OFN_EXTENSIONDIFFERENT = &H400
Public Const OFN_PATHMUSTEXIST = &H800     'Can not use unexistant path name
Public Const OFN_FILEMUSTEXIST = &H1000    'Can not use unexistant file name
Public Const OFN_CREATEPROMPT = &H2000     'If there is no file,create or not.
Public Const OFN_EXPLORER = &H80000

'*********
'** Val **
'*********
'[Open file] and [Save File]Dialog
Private Type OPENFILENAME
        lStructSize As LongPtr     'Size
        hwndOwner As LongPtr      'Window's handle
        hInstance As LongPtr       'Apprication's instance
        lpstrFilter As String   'Filter
        lpstrCustomFilter As String
        nMaxCustFilter As LongPtr
        nFilterIndex As LongPtr    'Default file name
        lpstrFile As String     'Selected file name
        nMaxFile As LongPtr       'Max length of file name
        lpstrFileTitle As String
        nMaxFileTitle As LongPtr
        lpstrInitialDir As String
        lpstrTitle As String
        flags As LongPtr          'option
        nFileOffset As Integer
        nFileExtension As Integer
        lpstrDefExt As String
        lCustData As LongPtr
        lpfnHook As LongPtr
        lpTemplateName As String
End Type

'--------------------------------------------------------
'   FUNC    : ShowOpenFileDlg
'   aim     : Show [Open File]Dialog and get file name
'--------------------------------------------------------
Public Function ShowOpenFileDlg(lnghWnd As Long, strFilter As String, strDefDir As String) As String

    Dim strRePathName As String
     
    Dim typOpenFileName As OPENFILENAME
     
    With typOpenFileName
        'Set Size
        .lStructSize = Len(typOpenFileName)
        'Set owner windows handle
        .hwndOwner = lnghWnd
        'Set Apprication's instance
'        .hInstance = App.hInstance
        'Set filter
        .lpstrFilter = strFilter
        'Set active filter name
        .nFilterIndex = 1
        'Reset [File]box
        .lpstrFile = String(256, Chr(0))
        'Set max length of file name
        .nMaxFile = 256
        'pointer for Recieve file's title
        .lpstrFileTitle = String(256, Chr(0))
        'Set max length of file title
        .nMaxFileTitle = 256
        'Set default directory
        .lpstrInitialDir = strDefDir
        'Set dialog's title
        .lpstrTitle = "Select File"
        'Set option
        .flags = OFN_EXPLORER Or OFN_PATHMUSTEXIST _
            Or OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY

    End With
     
    'Show [Open File]Dialog
    If GetOpenFileName(typOpenFileName) = 0 Then
        'When Cancel
        ShowOpenFileDlg = ""
    Else
        'If OK,show file name
        'purge Null strings
        ShowOpenFileDlg = Left(typOpenFileName.lpstrFile, _
               InStr(typOpenFileName.lpstrFile, vbNullChar) - 1)
    End If

End Function
5 @R18063
ต้องแก้บางบรรทัดครับ ผมเคยโพสให้แล้วที่นี่ครับ

http://www.thai-access.com/yeadram_view.php?topic_id=3750
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.2236s