Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28
  1. #16
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,689
    Whilst I could provide a conversion for those APIs, that code is very outdated and better methods are now available for browsing folders and opening selected files..



    Please look at the link to my website provided by both @welshgasman and myself.
    The shift bypass code is MUCH simpler and won't need converting for 64-bit.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  2. #17
    phil12586 is offline Novice
    Windows 10 Office 365
    Join Date
    Oct 2022
    Posts
    11
    Option Compare Database
    Option Explicit


    '***************** Code Start **************
    'This code was originally written by Ken Getz.
    '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:
    ' Microsoft Access 95 How-To
    ' Ken Getz and Paul Litwin
    ' Waite Group Press, 1996


    Type tagOPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    strFilter As String
    strCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    strFile As String
    nMaxFile As Long
    strFileTitle As String
    nMaxFileTitle As Long
    strInitialDir As String
    strTitle As String
    Flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    strDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
    End Type


    Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
    Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean


    Declare Function aht_apiGetSaveFileName Lib "comdlg32.dll" _
    Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As Boolean

    Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long


    Global Const ahtOFN_READONLY = &H1
    Global Const ahtOFN_OVERWRITEPROMPT = &H2
    Global Const ahtOFN_HIDEREADONLY = &H4
    Global Const ahtOFN_NOCHANGEDIR = &H8
    Global Const ahtOFN_SHOWHELP = &H10
    ' You won't use these.
    'Global Const ahtOFN_ENABLEHOOK = &H20
    'Global Const ahtOFN_ENABLETEMPLATE = &H40
    'Global Const ahtOFN_ENABLETEMPLATEHANDLE = &H80
    Global Const ahtOFN_NOVALIDATE = &H100
    Global Const ahtOFN_ALLOWMULTISELECT = &H200
    Global Const ahtOFN_EXTENSIONDIFFERENT = &H400
    Global Const ahtOFN_PATHMUSTEXIST = &H800
    Global Const ahtOFN_FILEMUSTEXIST = &H1000
    Global Const ahtOFN_CREATEPROMPT = &H2000
    Global Const ahtOFN_SHAREAWARE = &H4000
    Global Const ahtOFN_NOREADONLYRETURN = &H8000
    Global Const ahtOFN_NOTESTFILECREATE = &H10000
    Global Const ahtOFN_NONETWORKBUTTON = &H20000
    Global Const ahtOFN_NOLONGNAMES = &H40000
    ' New for Windows 95
    Global Const ahtOFN_EXPLORER = &H80000
    Global Const ahtOFN_NODEREFERENCELINKS = &H100000
    Global Const ahtOFN_LONGNAMES = &H200000


    Function TestIt()
    Dim strFilter As String
    Dim lngFlags As Long


    strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)", "*.MDA;*.MDB")
    strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF")
    strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
    strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")


    MsgBox "You selected: " & ahtCommonFileOpenSave(InitialDir:="C:", _
    Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
    DialogTitle:="Hello! Open Me!")
    ' Since you passed in a variable for lngFlags,
    ' the function places the output flags value in the variable.
    Debug.Print Hex(lngFlags)

    End Function


    Function GetOpenFile(Optional varDirectory As Variant, _
    Optional varTitleForDialog As Variant) As Variant
    ' Here's an example that gets an Access database name.
    Dim strFilter As String
    Dim lngFlags As Long
    Dim varFileName As Variant


    ' Specify that the chosen file must already exist, don't change directories when you're done
    ' Also, don't bother displaying the read-only box. It'll only confuse people.
    lngFlags = ahtOFN_FILEMUSTEXIST Or _
    ahtOFN_HIDEREADONLY Or ahtOFN_NOCHANGEDIR

    If IsMissing(varDirectory) Then
    varDirectory = ""
    End If


    If IsMissing(varTitleForDialog) Then
    varTitleForDialog = ""
    End If


    ' Define the filter string and allocate space in the "c"
    ' string Duplicate this line with changes as necessary for more file templates.
    strFilter = ahtAddFilterItem(strFilter, "Access (*.mdb)", "*.MDB;*.MDA")
    ' Now actually call to get the file name.
    varFileName = ahtCommonFileOpenSave( _
    OpenFile:=True, _
    InitialDir:=varDirectory, _
    Filter:=strFilter, _
    Flags:=lngFlags, _
    DialogTitle:=varTitleForDialog)
    If Not IsNull(varFileName) Then
    varFileName = TrimNull(varFileName)
    End If


    GetOpenFile = varFileName


    End Function


    Function ahtCommonFileOpenSave( _
    Optional ByRef Flags As Variant, _
    Optional ByVal InitialDir As Variant, _
    Optional ByVal Filter As Variant, _
    Optional ByVal FilterIndex As Variant, _
    Optional ByVal DefaultExt As Variant, _
    Optional ByVal FileName As Variant, _
    Optional ByVal DialogTitle As Variant, _
    Optional ByVal hwnd As Variant, _
    Optional ByVal OpenFile As Variant) As Variant
    ' This is the entry point you'll use to call the common file open/save dialog.
    ' The parameters are listed below, and all are optional.
    '
    ' In:
    ' Flags: one or more of the ahtOFN_* constants, OR'd together.
    ' InitialDir: the directory in which to first look
    ' Filter: a set of file filters, set up by calling
    ' AddFilterItem. See examples.
    ' FilterIndex: 1-based integer indicating which filter
    ' set to use, by default (1 if unspecified)
    ' DefaultExt: Extension to use if the user doesn't enter one.
    ' Only useful on file saves.
    ' FileName: Default value for the file name text box.
    ' DialogTitle: Title for the dialog.
    ' hWnd: parent window handle
    ' OpenFile: Boolean(True=Open File/False=Save As)
    ' Out:
    ' Return Value: Either Null or the selected filename
    Dim OFN As tagOPENFILENAME
    Dim strFileName As String
    Dim strFileTitle As String
    Dim fResult As Boolean


    ' Give the dialog a caption title.
    If IsMissing(InitialDir) Then InitialDir = CurDir
    If IsMissing(Filter) Then Filter = ""
    If IsMissing(FilterIndex) Then FilterIndex = 1
    If IsMissing(Flags) Then Flags = 0&
    If IsMissing(DefaultExt) Then DefaultExt = ""
    If IsMissing(FileName) Then FileName = ""
    If IsMissing(DialogTitle) Then DialogTitle = ""
    If IsMissing(hwnd) Then hwnd = Application.hWndAccessApp
    If IsMissing(OpenFile) Then OpenFile = True
    ' Allocate string space for the returned strings.
    strFileName = Left(FileName & String(256, 0), 256)
    strFileTitle = String(256, 0)
    ' Set up the data structure before you call the function
    With OFN
    .lStructSize = Len(OFN)
    .hwndOwner = hwnd
    .strFilter = Filter
    .nFilterIndex = FilterIndex
    .strFile = strFileName
    .nMaxFile = Len(strFileName)
    .strFileTitle = strFileTitle
    .nMaxFileTitle = Len(strFileTitle)
    .strTitle = DialogTitle
    .Flags = Flags
    .strDefExt = DefaultExt
    .strInitialDir = InitialDir
    ' Didn't think most people would want to deal with these options.
    .hInstance = 0
    '.strCustomFilter = ""
    '.nMaxCustFilter = 0
    .lpfnHook = 0
    'New for NT 4.0
    .strCustomFilter = String(255, 0)
    .nMaxCustFilter = 255
    End With


    ' This will pass the desired data structure to the
    ' Windows API, which will in turn it uses to display the Open/Save As Dialog.
    If OpenFile Then
    fResult = aht_apiGetOpenFileName(OFN)
    Else
    fResult = aht_apiGetSaveFileName(OFN)
    End If


    ' The function call filled in the strFileTitle member
    ' of the structure. You'll have to write special code
    ' to retrieve that if you're interested.
    If fResult Then
    ' You might care to check the Flags member of the
    ' structure to get information about the chosen file.
    ' In this example, if you bothered to pass in a
    ' value for Flags, we'll fill it in with the outgoing Flags value.
    If Not IsMissing(Flags) Then Flags = OFN.Flags
    ahtCommonFileOpenSave = TrimNull(OFN.strFile)
    Else
    ahtCommonFileOpenSave = vbNullString
    End If


    End Function


    Function ahtAddFilterItem(strFilter As String, _
    strDescription As String, Optional varItem As Variant) As String

    ' Tack a new chunk onto the file filter.
    ' That is, take the old value, stick onto it the description,
    ' (like "Databases"), a null character, the skeleton
    ' (like "*.mdb;*.mda") and a final null character.


    If IsMissing(varItem) Then varItem = "*.*"


    ahtAddFilterItem = strFilter & strDescription & vbNullChar & varItem & vbNullChar


    End Function


    Private Function TrimNull(ByVal strItem As String) As String
    Dim intPos As Integer


    intPos = InStr(strItem, vbNullChar)


    If intPos > 0 Then
    TrimNull = Left(strItem, intPos - 1)
    Else
    TrimNull = strItem
    End If


    End Function

  3. #18
    phil12586 is offline Novice
    Windows 10 Office 365
    Join Date
    Oct 2022
    Posts
    11
    sorry for the double post

  4. #19
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    257
    One of the easiest ways is to have a button on say, the login or your welcome screen form. codes will be applied to the button. By that way, you will be prompted to enter your password to unlock the database when you click on the button. In order to lock the database, just enter a wrong password and the shift bypass will be locked.

  5. #20
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    257

  6. #21
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    257
    Quote Originally Posted by Emmanuel View Post
    enter your password at this section

    ď strInput = "Please enter Your password here"

  7. #22
    phil12586 is offline Novice
    Windows 10 Office 365
    Join Date
    Oct 2022
    Posts
    11
    thanks for the help, but the problem is that all my DB's have the Shift Bypass disabled, so i cant get into them to even add anything if i wanted. if someone could just look at the code that i posted. it looks like the problem is in red. again i don't know a thing about code and very little about modules. but i was able to find that the issue has something to do with "declare Function" and replacing it with PtrSafe believe. but i know nothing about this. ive tried to fix it myself, but would not work. again, don't know what I'm doing.
    thanks in advance.

    this is the original code:
    Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _ Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean


    Declare Function aht_apiGetSaveFileName Lib "comdlg32.dll" _
    Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As Boolean

    Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long



    and this is what i found:
    #If VBA7 Then
    Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal ms As LongPtr)
    #Else
    Private Declare Sub Sleep Lib "kernel32" (ByVal ms as Long)
    #End If

  8. #23
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    257
    Quote Originally Posted by phil12586 View Post
    thanks for the help, but the problem is that all my DB's have the Shift Bypass disabled, so i cant get into them to even add anything if i wanted. if someone could just look at the code that i posted. it looks like the problem is in red. again i don't know a thing about code and very little about modules. but i was able to find that the issue has something to do with "declare Function" and replacing it with PtrSafe believe. but i know nothing about this. ive tried to fix it myself, but would not work. again, don't know what I'm doing.
    thanks in advance.

    this is the original code:
    Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _ Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean


    Declare Function aht_apiGetSaveFileName Lib "comdlg32.dll" _
    Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As Boolean

    Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long



    and this is what i found:
    #If VBA7 Then
    Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal ms As LongPtr)
    #Else
    Private Declare Sub Sleep Lib "kernel32" (ByVal ms as Long)
    #End If

    If thatís the case, then I suggest u create a new db and import all your tables, queries, forms, reports and all modules excluding the modules that disables the shift.

    Then you can go ahead and apply the codes I sent you

  9. #24
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    257
    The shift bypass modules can be quite frustrating. Trust me, I have been in your shoes before.

    Try what I said and you will be good to go

  10. #25
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    11,976
    Can somebody explain what that code has to do with a shift bypass problem? I've already stated it has no bearing, but no one disputed that or backed it up. If I'm wrong then please educate me. If there is a problem with it, fixing it won't solve the issue as far as I can tell.

    Maybe post a copy of the file that you can't get into and someone can see what's going on with it.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #26
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    257
    I made some changes on your database using the suggestions i gave you. You may have to forgo your initial module and use mine to make it work.

    Click on the button (L0CK/UNLOCK)
    Enter the correct password to enable the shift bypass.

    Also, enter a wrong password to disable to shift by-pass.

    With this, you can choose to either lock or unlock anytime you wish.

    Default password as been set to : 12345

    Good Luck
    Attached Files Attached Files

  12. #27
    phil12586 is offline Novice
    Windows 10 Office 365
    Join Date
    Oct 2022
    Posts
    11
    just seeing this, i will definitely be giving it a try.
    thank you, i will let you know if it works.

  13. #28
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    257
    Quote Originally Posted by phil12586 View Post
    just seeing this, i will definitely be giving it a try.
    thank you, i will let you know if it works.
    Great. All the best

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Bypass (Shift) key not disabled
    By skydivetom in forum Forms
    Replies: 6
    Last Post: 07-13-2019, 08:16 AM
  2. Shift key doesn't bypass ODBC connection
    By Glenn_Suggs in forum Import/Export Data
    Replies: 4
    Last Post: 01-06-2019, 09:48 AM
  3. Enabling shift bypass
    By reynier09 in forum Access
    Replies: 4
    Last Post: 08-18-2016, 08:25 PM
  4. Secuuring the SHIFT bypass function
    By awhittle23 in forum Security
    Replies: 1
    Last Post: 06-22-2016, 06:09 PM
  5. Replies: 3
    Last Post: 06-22-2016, 04:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums