Results 1 to 6 of 6

Need Update Help on Old Module

  1. #1
    ortizimo is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jun 2017
    Location
    FL
    Posts
    48

    Need Update Help on Old Module

    I've had this module for years and now I'm using it again, but now I see its incomplete. The main issue is that when I cancel the cover browsing it returns with a No Cover Selected message (which is fine), but if a cover was already selected it removes it and I have to reselect it.

    All I'm trying to do is fix is that if decide not to select a cover to cancel the process (as it does) and return to the main page without removing the cover. Hope I'm making my issue clear. Below is the code in the Select Button and the called module:

    --------------------
    Select Button
    --------------------
    Private Sub Browse_Click()
    Me.ImagePath = LaunchCD(Me)
    Me.Requery
    MsgBox "Record Saved!"
    End Sub

    --------------------
    Module
    --------------------

    ' This code only works with Access 32bit '

    Private Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" Alias _
    "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

    Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
    End Type

    Function LaunchCD(strform As Form) As String
    Dim OpenFile As OPENFILENAME
    Dim lReturn As Long
    Dim sFilter As String
    OpenFile.lStructSize = Len(OpenFile)
    OpenFile.hwndOwner = strform.Hwnd
    sFilter = "All Files (*.*)" & Chr(0) & "*.*" & Chr(0) & _
    "JPEG Files (*.JPG)" & Chr(0) & "*.JPG" & Chr(0)
    OpenFile.lpstrFilter = sFilter
    OpenFile.nFilterIndex = 1
    OpenFile.lpstrFile = String(257, 0)
    OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
    OpenFile.lpstrFileTitle = OpenFile.lpstrFile
    OpenFile.nMaxFileTitle = OpenFile.nMaxFile
    'Change directory location below'
    OpenFile.lpstrInitialDir = "C:\retrogamesDB\CoverArt"
    OpenFile.lpstrTitle = "Select a file"
    OpenFile.flags = 0
    lReturn = GetOpenFileName(OpenFile)
    If lReturn = 0 Then
    MsgBox "A file was not selected!", vbInformation, _
    "Please select a file"
    Else


    LaunchCD = Trim(Left(OpenFile.lpstrFile, InStr(1, OpenFile.lpstrFile, vbNullChar) - 1))
    End If
    End Function

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    42,638
    Please post lengthy code within CODE tags to retain indentation and readability.

    What do you mean by 'removing the cover' - remove from where - a combobox?
    To provide db: Make copy, remove confidential data, run compact & repair, zip w/Windows Compression if over 500KB (2MB zip allowed), attach to post. Attachment Manager is below the Advanced post editor window, click Go Advanced below the Quick Reply window.
    If any suggestion resolves your issue, please use the Thread Tools dropdown above first post and mark as Solved!

    Debug!Debug!Debug! http://www.cpearson.com/excel/debug.htm

  3. #3
    ortizimo is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jun 2017
    Location
    FL
    Posts
    48
    Quote Originally Posted by June7 View Post
    Please post lengthy code within CODE tags to retain indentation and readability.

    What do you mean by 'removing the cover' - remove from where - a combobox?
    Sorry but the posted code is as is...

    If I no longer want to browse for a cover in my hdd and select cancel, if a cover pic was already select and displaying on screen it removes it from the screen then I actually have to go and find it again.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    42,638
    Tested code. All it does is return a text string for file path, doesn't open image file. So I still don't understand the issue.
    To provide db: Make copy, remove confidential data, run compact & repair, zip w/Windows Compression if over 500KB (2MB zip allowed), attach to post. Attachment Manager is below the Advanced post editor window, click Go Advanced below the Quick Reply window.
    If any suggestion resolves your issue, please use the Thread Tools dropdown above first post and mark as Solved!

    Debug!Debug!Debug! http://www.cpearson.com/excel/debug.htm

  5. #5
    ortizimo is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jun 2017
    Location
    FL
    Posts
    48
    Quote Originally Posted by June7 View Post
    Tested code. All it does is return a text string for file path, doesn't open image file. So I still don't understand the issue.
    works fine here as is...the first part is a button the second goes in a module...you can name it cover...then when i click the button i can browse for the pic i want and use it...see pic below... Click image for larger version. 

Name:	accessforums.PNG 
Views:	8 
Size:	184.1 KB 
ID:	31517

    if I decide to NOT select a pic, instead of leaving the pic as is, it removes it...see below...
    Click image for larger version. 

Name:	accessforums.PNG 
Views:	9 
Size:	32.8 KB 
ID:	31518

    All i'm trying to do is fix this so it doesnt remove the pic if I cancel the browsing....

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    42,638
    Change the Browse code to:

    Code:
    Private Sub Browse_Click()
        Dim strImage As String
        strImage = LaunchCD(Me)
        If strImage <> "" Then
            Me.ImagePath = strImage
            Me.Requery
            MsgBox "Image Saved!"
        End If
     End Sub
    To provide db: Make copy, remove confidential data, run compact & repair, zip w/Windows Compression if over 500KB (2MB zip allowed), attach to post. Attachment Manager is below the Advanced post editor window, click Go Advanced below the Quick Reply window.
    If any suggestion resolves your issue, please use the Thread Tools dropdown above first post and mark as Solved!

    Debug!Debug!Debug! http://www.cpearson.com/excel/debug.htm

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 14
    Last Post: 08-19-2013, 08:37 AM
  2. What is Module?
    By glen in forum Modules
    Replies: 1
    Last Post: 09-14-2012, 08:11 AM
  3. class module vs regular module
    By Madmax in forum Modules
    Replies: 1
    Last Post: 05-01-2012, 02:44 PM
  4. Run a Module
    By mchadwick in forum Modules
    Replies: 7
    Last Post: 09-02-2011, 08:24 AM
  5. Replies: 4
    Last Post: 05-16-2011, 03:58 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
  •  
Tech Forums: Microsoft Office Forums