Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2009
    Posts
    28

    Unhappy Unanswered: Access 2003 : unix interface

    I have designed a simple form which maintains a table of report names.
    Each report name corresponds to a source file on a unix server in a particular directory.
    I want the user to be able to click on a command button, or anything else available to me in Access, so that they are then directed to the unix host, and are either in a shell in the correct directory, or if possible, in a 'vi' session with the correct source file selected.
    When finished, they should then be automatically redirected back to the Access session.
    Is this possible ?
    I am new to Access.
    Many thanks in anticipation.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    The least I can say is that for a beginner you don't start with an easy one!

    I'm not sure if I can help or not, mainly because there are several years since I last worked with Unix systems, and at the time I had a Vax to help me (that's an old joke that was very popular: How do you have two Unix systems communicate with each other ? Put a Vax in between).

    However, what I would do would be to use a terminal emulator to open a session on the Unix system. Some of those emulators can receive command arguments which are valid Unix commands or the name of a script file they execute when they are called. I don't know what's available today but I remember programs such as E-Term32, TeraTerm and a few others.

    Inside Access the solution is rather simple : Build a command line or a command argument and call the Emulator, passing it the string you just built. If the terminal emulator can execute a remote command file, you can use an FTP OCX (or Com) object to copy the command file you build to the appropriate directory on the Unix system, then call the emulator.

    You can shell the emulator program and make it modal for Access in several ways, here is one:

    Code:
    Option Compare Database
    Option Explicit
    
    Rem
    Rem Created rf 13.02.2000
    Rem
    Rem Launch external app
    Rem and wait for user exit before continuing Main App
    Rem
    Rem Works on Win NT 4.0 and beyond
    Rem
    Rem Procedure to follow if used to manage external text file
    Rem with i.e. worpad.exe
    Rem
    Rem Case One : new file
    Rem         Create an empty file (i.e. in Temp directory)
    Rem         call sub with wordpad and the text file name
    Rem         when back in app, copy it in storage directory
    Rem
    Rem    Dim Channel As Integer
    Rem    Channel = FreeFile
    Rem    Open "c:\lulu.txt" For Output As Channel
    Rem    Close Channel
    Rem    LauchAndWaitForUserExit "c:\program files\windows nt\accessoires\wordpad.exe", "c:\lulu.txt"
    Rem
    Rem
    Rem Case Two : the file exists
    Rem
    Rem         Copy the file from storage directory
    Rem            (i.e. in Temp directory)
    Rem         call sub with wordpad and the text file name
    Rem         when back in app, copy it in storage directory
    Rem
    Rem Note : Could be enhanced by checking if file was modified
    Rem
    
    Private Type STARTUPINFO
        cb As Long
        lpReserved As String
        lpDesktop As String
        lpTitle As String
        dwX As Long
        dwY As Long
        dwXSize As Long
        dwYSize As Long
        dwXCountChars As Long
        dwYCountChars As Long
        dwFillAttribute As Long
        dwFlags As Long
        wShowWindow As Integer
        cbReserved2 As Integer
        lpReserved2 As Long
        hStdInput As Long
        hStdOutput As Long
        hStdError As Long
    End Type
    
    Private Type PROCESS_INFORMATION
        hProcess As Long
        hThread As Long
        dwProcessID As Long
        dwThreadID As Long
    End Type
    
    Private Const NORMAL_PRIORITY_CLASS = &H20&
    Private Const INFINITE = -1&
    
    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
             hHandle As Long, ByVal dwMilliseconds As Long) As Long
    
    Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
             lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
             lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
             ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
             ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
             lpStartupInfo As STARTUPINFO, lpProcessInformation As _
             PROCESS_INFORMATION) As Long
    
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    
    Sub LauchAndWaitForUserExit(AppSpec As String, Optional FileSpec As String)
        
        If IsMissing(FileSpec) Then
            ExecCmd (AppSpec)
        Else
            ExecCmd (AppSpec & "  " & FileSpec)
        End If
    
    End Sub
    
    Public Sub ExecCmd(cmdline$)
    
        Dim NameOfProc As PROCESS_INFORMATION
        Dim start As STARTUPINFO
        Dim ReturnValue As Integer
        
        ' Initialize the STARTUPINFO structure
        start.cb = Len(start)
        
        ' Start the shelled application
        ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, NameOfProc)
        ReturnValue = WaitForSingleObject(NameOfProc.hProcess, INFINITE)
        ReturnValue = CloseHandle(NameOfProc.hProcess)
    
    End Sub
    Have a nice day!

  3. #3
    Join Date
    Jul 2009
    Posts
    28

    Smile

    Thanks for your contribution.
    In fact, I no longer need this level of access, as the sources will now to stored elsewhere.
    I appreciate your advice, which may come in handy if I ever need to perform a similar exercise.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •