Results 1 to 6 of 6

Thread: Calling another executable

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    325

    Calling another executable

    When I click a button which is supposed to call an executable which is a time clock program, I get an error each time that says " no current record". This happens when "timer" is called. Any ideas?
    Code:
    Private Sub cmdInOut_Click()
        Dim wSS As Workspace
        Dim ssDB As DAO.Database
        Dim retVal, xs As String
        
        lt = TimeValue(Now)
    
        Set wSS = CreateWorkspace("", "admin", "", dbUseJet)
        Set ssDB = wSS.OpenDatabase(sysDBPath & "")
        ssDB.Execute "DELETE * FROM timeKeeping WHERE rID=" & registerID, dbFailOnError
        tk = Now
             
        On Error Resume Next
        xs = ssDB.TableDefs("timeKeeping").Fields("prog").Name
        On Error GoTo 0
        If xs <> "prog" Then
            ssDB.TableDefs("timeKeeping").Fields.Append _
            ssDB.TableDefs("timeKeeping").CreateField("prog", dbText)
            ssDB.TableDefs("timeKeeping").Fields("prog").DefaultValue = ""
            ssDB.Execute "UPDATE timeKeeping SET prog=''", dbFailOnError
        End If
        
        xs = ""
        On Error Resume Next
        xs = ssDB.TableDefs("timeKeeping").Fields("printer").Name
        On Error GoTo 0
        If xs <> "printer" Then
            ssDB.TableDefs("timeKeeping").Fields.Append _
            ssDB.TableDefs("timeKeeping").CreateField("printer", dbText)
            ssDB.TableDefs("timeKeeping").Fields("printer").DefaultValue = ""
            ssDB.Execute "UPDATE timeKeeping SET printer=''", dbFailOnError
        End If
        
        xs = ""
       
        setDefaultPrinter
        
        If registerID < 0 Then setRegisterParameters
        
        ssDB.Execute "INSERT INTO timeKeeping (currDate,rID,coNum,prog,printer) " & _
                     "VALUES(#" & tk & "#," & registerID & "," & comp & _
                     ",'FB',""" & Printer.DeviceName & """)", dbFailOnError
        Set ssDB = Nothing
        Set wSS = Nothing
        
        pcKB.Enabled = False
        xs = "C:\Aces Projects\TM\Timer.Exe "
        retVal = Shell(xs, 1)   ' Run Timer.Exe
        AppActivate retVal      ' Activate the Timer.Exe
        SendKeys tk
        timerTK.Enabled = True
    End Sub
    
    Private Sub cmdM_Click(Index As Integer)
        Dim i As Integer
        
        If txt.Visible = False Then Exit Sub
        
        i = ss 'txt.SelStart
        
        Select Case Index
        Case 0
            If i > 0 Then i = i - 1                     'vbKeyLeft
        Case 1
            If i < Len(txt) Then i = i + 1              'vbKeyRight
        Case 2
            txt = Left(txt, i) & " " & Mid(txt, i + 1)  'vbKeySpace
            i = i + 1
        End Select
        txt.SetFocus
        txt.SelStart = i
        ss = i
    End Sub
    Last edited by Hack; Feb 28th, 2008 at 11:53 AM. Reason: Added Code Tags

  2. #2

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    325

    Re: Calling another executable

    I am sorry but I don't know what you mean--is there a link that explains this?

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Calling another executable

    1. Click the Edit button for your original post
    2. Click Go Advanced
    3. Select your code and click Code (icon with white background)

    Or you can type the code html tags before and after then code:

    [code]your code goes here[/ code] <<< no spaces inside brackets

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Calling another executable

    I edited your post and put in Code Tags.

    The syntax is: [code]your code goes here[/code]

    Use ShellExecute instead of Shell.
    Code:
    Option Explicit
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
    ByVal lpParameters As String, ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long
    
    Private Const SW_SHOWNORMAL = 1
    
    Private Sub Command1_Click()
    ShellExecute Me.hwnd, vbNullString, "C:\Aces Projects\TM\Timer.Exe", vbNullString, "C:\", SW_SHOWNORMAL
    End Sub

  6. #6

Posting Permissions

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



Click Here to Expand Forum to Full Width