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
Re: Calling another executable
Can you wrap your code with CODE tags please?
Re: Calling another executable
I am sorry but I don't know what you mean--is there a link that explains this?
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
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
Re: Calling another executable
What does shelling external program and retrieving data from db have in common?
What is your Timer.Exe supposed to do?