NWildblood
Technical User
Hi, I am currently running some work in Attachmate Extra from some VBA in an Access module. It works fine except for the If Then actions required dependendent on various Extra screen messages. The code in question is below the line:
'actions if messages
I'm sure it's just my If... Then arguments, but cannot get the VB to Enter "Y" where required, once or any further times - can anyone see an obvious oversight in my code ??? Many thanks
________________________________________________________
Sub CreateJobs() 'to run from the sdhmatches spreadsheet produced by the cert engine
Dim oDB As Database 'ACCESS CODE
Dim oRS As DAO.Recordset 'ACCESS CODE
Dim vSomeVal
Dim System As Object, Sessions As Object, Sess As Object, CSS As Object
Dim msg_line As String
Set System = CreateObject("EXTRA.System") ' Gets the system object
If (System Is Nothing) Then
MsgBox "Could not create the EXTRA System object. Stopping macro playback."
Stop
End If
Set Sessions = System.Sessions
If (Sessions Is Nothing) Then
MsgBox "Could not create the Sessions collection object. Stopping macro playback."
Stop
End If
Set CSS = GetObject("C:\Documents and Settings\zeicri\Desktop\SMNXS06.edp")
Set Sess = System.ActiveSession
Set oDB = OpenDatabase("S:\CommonARUK01\FinAccouUK01\Fixed Asset\SDH\SDH CERTIFICATIONS\CERTIFICATION DATABASE") 'ACCESS CODE
Set oRS = oDB.OpenRecordset("BP INFORMATION") 'ACCESS CODE
If (Sess Is Nothing) Then
MsgBox "Could not create the Session object. Stopping macro playback."
Stop
End If
If Not Sess.Visible Then Sess.Visible = True
msg_line = Trim(Sess.Screen.GetString(24, 1, Sess.Screen.Cols))
Sess.Screen.SendKeys ("<Home>AJOB<Enter>")
Call Wait(Sess)
If Not oRS.BOF Then
oRS.MoveFirst
Do While Not oRS.EOF
'create job between here
Sess.Screen.SendKeys ("HQJOB<NewLine><Tab>IPT") 'HQJOB
Sess.Screen.SendKeys Trim(oRS.Fields("New Project").Value) 'PROJECT
Sess.Screen.SendKeys ("<NewLine>MX")
Sess.Screen.SendKeys Trim(oRS.Fields("New COW").Value) 'COW - TAB REQUIRED IF NOT 5 CHAR
Sess.Screen.SendKeys ("<Tab>")
Sess.Screen.SendKeys Trim(oRS.Fields("New APC").Value) 'APC
Sess.Screen.SendKeys ("<NewLine><NewLine>")
Sess.Screen.SendKeys Trim(oRS.Fields("New Job Title").Value) 'TITLE
Sess.Screen.SendKeys ("<NewLine>")
Sess.Screen.SendKeys Trim(oRS.Fields("New Job Title").Value) 'DESC
Sess.Screen.SendKeys ("<NewLine>")
Sess.Screen.SendKeys Trim(oRS.Fields("Start Date").Value)
Sess.Screen.SendKeys Trim(oRS.Fields("End Date").Value)
Sess.Screen.SendKeys Trim(oRS.Fields("Req date").Value)
Sess.Screen.SendKeys ("<Delete><EraseEOF><Tab><Delete><EraseEOF>")
Sess.Screen.SendKeys Trim(oRS.Fields("Locn A").Value) '1141
Sess.Screen.SendKeys ("<NewLine><NewLine>")
Sess.Screen.SendKeys Trim(oRS.Fields("Planners EIN").Value) 'EIN
Sess.Screen.SendKeys ("<Enter>")
Call Wait(Sess)
'and here
'actions if messages
If InStr(1, UCase(msg_line), UCase("TW007 - Required by Date less than End Date")) > 0 Then
Sess.Screen.PutString "y", 21, 78
Sess.Screen.SendKeys ("<Enter>")
Call Wait(Sess)
End If
Call Wait(Sess)
If InStr(1, UCase(msg_line), UCase("TW015 - Start Date is less than Current Date; Confirm Y/N")) > 0 Then
Sess.Screen.PutString "y", 21, 78
Sess.Screen.SendKeys ("<Enter>")
Call Wait(Sess)
End If
Call Wait(Sess)
If InStr(1, UCase(msg_line), UCase("TW021 COW is applicable to both PFC & PROACT; Confirm Y/N")) > 0 Then
Sess.Screen.PutString "y", 21, 78
Sess.Screen.SendKeys ("<Enter>")
Call Wait(Sess)
End If
Call Wait(Sess)
If InStr(1, UCase(msg_line), UCase("TW034 - Creating Job for HQ , confirm Y/N")) > 0 Then
Sess.Screen.PutString "y", 21, 78
Sess.Screen.SendKeys ("<Enter>")
Call Wait(Sess)
End If
Call Wait(Sess)
'get the job number
oRS.Edit
oRS.Fields("New Job").Value = Trim(Sess.Screen.GetString(22, 30, 6))
oRS.Update
Call Wait(Sess)
oRS.MoveNext
' Sess.Screen.SendKeys ("<Pf9>") 'TO OBSERVE SNAFU ORIGIN
' Call Wait(Sess)
Loop
End If
MsgBox "DONE", vbOKOnly, "End of Batch"
End Sub
________________________________________________
Private Sub Wait(Sess As Object)
Do While Sess.Screen.OIA.XStatus <> 0
DoEvents
Loop
End Sub
"No-one got everything done by Friday except Robinson Crusoe...
'actions if messages
I'm sure it's just my If... Then arguments, but cannot get the VB to Enter "Y" where required, once or any further times - can anyone see an obvious oversight in my code ??? Many thanks
________________________________________________________
Sub CreateJobs() 'to run from the sdhmatches spreadsheet produced by the cert engine
Dim oDB As Database 'ACCESS CODE
Dim oRS As DAO.Recordset 'ACCESS CODE
Dim vSomeVal
Dim System As Object, Sessions As Object, Sess As Object, CSS As Object
Dim msg_line As String
Set System = CreateObject("EXTRA.System") ' Gets the system object
If (System Is Nothing) Then
MsgBox "Could not create the EXTRA System object. Stopping macro playback."
Stop
End If
Set Sessions = System.Sessions
If (Sessions Is Nothing) Then
MsgBox "Could not create the Sessions collection object. Stopping macro playback."
Stop
End If
Set CSS = GetObject("C:\Documents and Settings\zeicri\Desktop\SMNXS06.edp")
Set Sess = System.ActiveSession
Set oDB = OpenDatabase("S:\CommonARUK01\FinAccouUK01\Fixed Asset\SDH\SDH CERTIFICATIONS\CERTIFICATION DATABASE") 'ACCESS CODE
Set oRS = oDB.OpenRecordset("BP INFORMATION") 'ACCESS CODE
If (Sess Is Nothing) Then
MsgBox "Could not create the Session object. Stopping macro playback."
Stop
End If
If Not Sess.Visible Then Sess.Visible = True
msg_line = Trim(Sess.Screen.GetString(24, 1, Sess.Screen.Cols))
Sess.Screen.SendKeys ("<Home>AJOB<Enter>")
Call Wait(Sess)
If Not oRS.BOF Then
oRS.MoveFirst
Do While Not oRS.EOF
'create job between here
Sess.Screen.SendKeys ("HQJOB<NewLine><Tab>IPT") 'HQJOB
Sess.Screen.SendKeys Trim(oRS.Fields("New Project").Value) 'PROJECT
Sess.Screen.SendKeys ("<NewLine>MX")
Sess.Screen.SendKeys Trim(oRS.Fields("New COW").Value) 'COW - TAB REQUIRED IF NOT 5 CHAR
Sess.Screen.SendKeys ("<Tab>")
Sess.Screen.SendKeys Trim(oRS.Fields("New APC").Value) 'APC
Sess.Screen.SendKeys ("<NewLine><NewLine>")
Sess.Screen.SendKeys Trim(oRS.Fields("New Job Title").Value) 'TITLE
Sess.Screen.SendKeys ("<NewLine>")
Sess.Screen.SendKeys Trim(oRS.Fields("New Job Title").Value) 'DESC
Sess.Screen.SendKeys ("<NewLine>")
Sess.Screen.SendKeys Trim(oRS.Fields("Start Date").Value)
Sess.Screen.SendKeys Trim(oRS.Fields("End Date").Value)
Sess.Screen.SendKeys Trim(oRS.Fields("Req date").Value)
Sess.Screen.SendKeys ("<Delete><EraseEOF><Tab><Delete><EraseEOF>")
Sess.Screen.SendKeys Trim(oRS.Fields("Locn A").Value) '1141
Sess.Screen.SendKeys ("<NewLine><NewLine>")
Sess.Screen.SendKeys Trim(oRS.Fields("Planners EIN").Value) 'EIN
Sess.Screen.SendKeys ("<Enter>")
Call Wait(Sess)
'and here
'actions if messages
If InStr(1, UCase(msg_line), UCase("TW007 - Required by Date less than End Date")) > 0 Then
Sess.Screen.PutString "y", 21, 78
Sess.Screen.SendKeys ("<Enter>")
Call Wait(Sess)
End If
Call Wait(Sess)
If InStr(1, UCase(msg_line), UCase("TW015 - Start Date is less than Current Date; Confirm Y/N")) > 0 Then
Sess.Screen.PutString "y", 21, 78
Sess.Screen.SendKeys ("<Enter>")
Call Wait(Sess)
End If
Call Wait(Sess)
If InStr(1, UCase(msg_line), UCase("TW021 COW is applicable to both PFC & PROACT; Confirm Y/N")) > 0 Then
Sess.Screen.PutString "y", 21, 78
Sess.Screen.SendKeys ("<Enter>")
Call Wait(Sess)
End If
Call Wait(Sess)
If InStr(1, UCase(msg_line), UCase("TW034 - Creating Job for HQ , confirm Y/N")) > 0 Then
Sess.Screen.PutString "y", 21, 78
Sess.Screen.SendKeys ("<Enter>")
Call Wait(Sess)
End If
Call Wait(Sess)
'get the job number
oRS.Edit
oRS.Fields("New Job").Value = Trim(Sess.Screen.GetString(22, 30, 6))
oRS.Update
Call Wait(Sess)
oRS.MoveNext
' Sess.Screen.SendKeys ("<Pf9>") 'TO OBSERVE SNAFU ORIGIN
' Call Wait(Sess)
Loop
End If
MsgBox "DONE", vbOKOnly, "End of Batch"
End Sub
________________________________________________
Private Sub Wait(Sess As Object)
Do While Sess.Screen.OIA.XStatus <> 0
DoEvents
Loop
End Sub
"No-one got everything done by Friday except Robinson Crusoe...