Results 1 to 7 of 7
  1. #1
    HS_1 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    103

    problem with shell function with Dlookup value


    HTML Code:
    I can't pass dLookup value to foldername when using shell function. 
    dLookup gives me the proper value but when I run this code it gets me to This PC/Documents. If I remove from Foldername string "curTransX" and run it again I end up in the proper subdirectory. 
    If dLookup output is for example "shop 1-002" I am expecting to see path "\\myPathToFolder\shop 1-002" passed to function, what I am getting is  "\\myPathToFolder\curTransX"  when debug.print Foldername.  
    Wonder what I am doing wrong here?
    Code:
    Private Sub txtPIsoRev_DblClick(Cancel As Integer) 
         
    
        Dim Foldername As String 
    
        Dim curTransX As Variant 
         
    
        curTransX = DLookup("[CurTrans]", "[tbl_Piping]", "[PipIsoDwg] ='" & Me.txtPIsoDwg & "'") 
    'Debug.Print curTransX 
         
        Foldername = "\\myPathToFolder\curTransX" 
        Debug.Print Foldername 
        Shell "C:\WINDOWS\explorer.exe """ & Foldername & "", vbNormalFocus 
    End Sub
    

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    8,986
    don't use shell for this, instead use this
    OpenNativeApp :

    Paste this code into a module, and it will open ANY file in its native application.
    usage: OpenNativeApp "c:\folder\file.pdf"
    will open it in acrobat
    and
    OpenNativeApp "c:\folder"
    will open the folder


    Code:
    'Attribute VB_Name = "modNativeApp"
    'Option Compare Database
    Option Explicit
    Code:
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub
    
    

  3. #3
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    8,986
    this website keep breaking the code into 2 blocks, but its all in 1 module.

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,373
    Maybe:

    Foldername = "\\myPathToFolder" & curTransX

    Not sure why but it won't let me put the \ between myPathToFolder and the last " in this reply which you need.

  5. #5
    HS_1 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    103
    Bulzie, I plugged in the "& curTransX after the end of path string but still have the same problem. Without last value (cuTrasX) from dLookup function the shell funtion woks but when I introduce the output from dLookup it takes me to my C:This PC\Documents. Basicly the shell function thinks that "curTransX" is the continuation of the path string whereas the continuation is output from dLookup. in my example "shop 1-002". 
    I was trying also use ranman256 function but I am getting compile error "Sub or Function not defied" pointing to OpenNativeApp


  6. #6
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,373
    Try
    Foldername = "\\myPathToFolder""" & curTransX & """"
    or
    Foldername = "\\myPathToFolder" & CStr(curTransX)

    Put a breakpoint on this line, open the form again and mouseover Foldername once it stops there to see what value it is putting in there so you can test different options.

  7. #7
    HS_1 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    103
    HTML Code:
    Thanks both strings work when I used your code and added forward slash after Folder
    
    Foldername = "\\myPathToFolder\""" & curTransX & """"
    
    
    
    
    
    
    
    
    
    Quote Originally Posted by Bulzie View Post
    Try
    Foldername = "\\myPathToFolder""" & curTransX & """"
    or
    Foldername = "\\myPathToFolder" & CStr(curTransX)

    Put a breakpoint on this line, open the form again and mouseover Foldername once it stops there to see what value it is putting in there so you can test different options.

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

Similar Threads

  1. Replies: 3
    Last Post: 02-11-2020, 02:44 PM
  2. Problem with Shell from Access
    By pgaccess in forum Access
    Replies: 13
    Last Post: 03-09-2017, 03:54 PM
  3. Weird problem with Call Shell
    By oatsybob in forum Programming
    Replies: 8
    Last Post: 07-04-2013, 12:02 AM
  4. dlookup function problem
    By bdaniel in forum Programming
    Replies: 3
    Last Post: 04-26-2010, 05:55 AM
  5. I have Problem in processing Dlookup Function
    By Katada in forum Programming
    Replies: 2
    Last Post: 04-23-2006, 12:07 AM

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