VBS Script that shows the files created on a specific date - date

I want to create a script that shows the files created on a specific date in a specific location.
As for now I created this:
Set objWMIService = GetObject("winmgmts:" & "!\\" & "." & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery ("Select * from CIM_DataFile where Drive='C:' AND Path='\\' AND CreationDate Like '20071107%' ")
For Each objFile in colFiles
Buffer = Buffer & objFile.FileName & " - " & objFile.CreationDate & vbNewLine
Next
Wscript.echo Buffer
But I am getting error in this line: " AND CreationDate Like '20071107%' "
So it does not work in such a way as I thought it will be - in C:\ I have a lot eula.txt files created on 2007 11 07.
I do not ask about finished code, but only for a clue. Thanks!

WHERE clause of a WQL query defends or inhibits from using wildcards in CIM_DATETIME values. Use SWbemDateTime object as follows:
option explicit
On Error GoTo 0
Dim strResult: strResult = Wscript.ScriptName
Dim objWMIService, colFiles, objFile, dTargetDate, dMinDate, dMaxDate, dateTime
Set dateTime = CreateObject("WbemScripting.SWbemDateTime")
dTargetDate = #2007-11-07# ' date literal in yyyy-mm-dd format
dateTime.SetVarDate( dTargetDate) ' convert to CIM_DATETIME
dMinDate = datetime
dateTime.SetVarDate( DateAdd( "d", 1, dTargetDate))
dMaxDate = datetime
strResult = strResult & vbNewLine & dMaxDate
Set objWMIService = GetObject("winmgmts:" & "!\\" & "." & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery ( _
"Select * from CIM_DataFile where Drive='c:' AND Path='\\'" _
& " AND CreationDate >= '" & dMinDate & "'" _
& " AND CreationDate < '" & dMaxDate & "'" _
)
If colFiles.Count = 0 Then
strResult = strResult & vbNewLine & "no files found"
Else
For Each objFile in colFiles
strResult = strResult & vbNewLine & objFile.FileName & " " & objFile.Extension _
& " - " & objFile.CreationDate
Next
End If
Wscript.Echo strResult
Wscript.Quit

Related

MS Access running SQL Stored Procedure Write Issue

I have managed to build a Access VBA query that runs a SQL Stored Procedure with parameters and seems to run and complete without incidence, however it does not write the data into the SQL Database. Am I missing a curtail part of coding?
The data is gathered from a form.
Function AddStaff()
Dim adoCN As New ADODB.Connection
Dim sConnString As String
Dim cmdObjCMD As New ADODB.Command
Dim BrandDataTxt
Dim StaffNameDataTxt
Dim NTloginIDDataTxt
Dim NMCUsernameDataTxt
Dim StaffAuditLevelDataTxt
Dim EmailAddressDataTxt
Dim PhoneLoginDataTxt
Dim TeamNameDataTxt
Dim TeamSegmentDataTxt
Dim StartDateDataTxt
Dim JobTitleDataTxt
DoCmd.OpenForm "AddNewStaff"
Forms!AddNewStaff.TBoxBrand.Value = BrandDataTxt
Forms!AddNewStaff.TBoxStaffName.Value = StaffNameDataTxt
Forms!AddNewStaff.TBoxPCLoginID.Value = NTloginIDDataTxt
Forms!AddNewStaff.TBoxNMCUsername.Value = NMCUsernameDataTxt
Forms!AddNewStaff.TBoxStaffAuditLevel.Value = CVar(StaffAuditLevelDataTxt)
Forms!AddNewStaff.TBoxEmailAddress.Value = EmailAddressDataTxt
Forms!AddNewStaff.TBoxPhoneLogin.Value = PhoneLoginDataTxt
Forms!AddNewStaff.TBoxTeamName.Value = TeamNameDataTxt
Forms!AddNewStaff.TBoxTeamSegment.Value = TeamSegmentDataTxt
Forms!AddNewStaff.TBoxStartDate.Value = CDate(StartDateDataTxt)
Forms!AddNewStaff.TBoxJobTitle.Value = JobTitleDataTxt
Set adoCN = New ADODB.Connection
sConnString = "Provider = SQLOLEDB; " & _
"Data Source = KCOMSQL26; " & _
"Initial Catalog = EclipseDW; " & _
"User ID = EclipseDW; " & _
"Password = M1Reporting; " & _
"Trusted_Connection = Yes; "
adoCN.Open sConnString
With cmdObjCMD
.ActiveConnection = sConnString
.CommandType = adCmdStoredProc
.CommandTimeout = 180
.CommandText = "Staff.usp_AddNewStaffMember"
.NamedParameters = True
.Parameters("#Brand") = " '" & BrandDataTxt & "'"
.Parameters("#StaffPrefName") = " '" & StaffNameDataTxt & "'"
.Parameters("#NTLoginID") = " '" & NTloginIDDataTxt & "'"
.Parameters("#NMCUsername") = " '" & NMCUsernameDataTxt & "'"
.Parameters("#StaffAuditLevel") = " " & StaffAuditLevelDataTxt & ""
.Parameters("#EmailAddress") = " '" & EmailAddressDataTxt & "'"
.Parameters("#PhoneLogin") = " '" & PhoneLoginDataTxt & "'"
.Parameters("#TeamName") = " '" & TeamNameDataTxt & "'"
.Parameters("#TeamSegment") = " '" & TeamSegmentDataTxt & "'"
.Parameters("#StartDate") = " " & StartDateDataTxt & ""
.Parameters("#JobTitle") = " '" & JobTitleDataTxt & "'"
.Execute
End With
adoCN.Close
End Function
SQL Code
EXEC staff.usp_AddNewStaffMember
#Brand = 'CSO North'
, #StaffPrefName = 'Test Agent'
, #NTLoginID = 'TestAgent'
, #NMCUsername = 'TestAgent'
, #StaffAuditLevel = '1'
, #EmailAddress = 'TestAgent#kcom.com'
, #PhoneLogin = '99999'
, #TeamName = 'Customer Services'
, #TeamSegment = 'Customer Services'
, #StartDate = '2017-04-18'
, #JobTitle = 'Test Agent'

How to test the internet connection behind a proxy?

I have this vbscript that works well on Windows 7 32-bit without proxy
In order to improve it, I seek for this solution: How to test internet connection behind a proxy ?
The solution perhaps it will be in VBScript or Powershell or Batch, much as I find a way to check whether i am connected or not behind a proxy !
The piece of code to improve it when i'm behind a proxy
If there is a trick to check if i'm connected to internet when i'm behind a proxy this is my question ?
If CheckConnection = true then
Msgbox "i'm connected to internet",vbinformation+vbSystemModal,"Check connection to internet"
Else
Msgbox "i'm not connected to internet",vbCritical+vbSystemModal,"Check connection to internet"
End if
'***************************************************************************
Function CheckConnection()
CheckConnection = False
strComputer = "smtp.gmail.com"
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery _
("select * from Win32_PingStatus where address = '" & strComputer & "'")
For Each objStatus in objPing
If objStatus.Statuscode = 0 Then
MyLoop = False
CheckConnection = True
Exit Function
End If
Next
End Function
'******************************************************************************
The hole code :
Option Explicit
Dim Title,MyScriptPath,DJBuzzRadio,MyLoop,strComputer,objPing,objStatus,FSO,FolderScript,URLICON,Icon
Title = "Radio DJ Buzz Live by © Hackoo © 2015"
MyScriptPath = WScript.ScriptFullName
Set FSO = Createobject("Scripting.FileSystemObject")
FolderScript = FSO.GetParentFolderName(MyScriptPath) 'Chemin du dossier ou se localise le Vbscript
Icon = FolderScript & "\akg.ico"
URLICON = ChrW(104)&ChrW(116)&ChrW(116)&ChrW(112)&ChrW(58)&ChrW(47)&ChrW(47)&ChrW(104)&ChrW(97)&ChrW(99)&ChrW(107)&ChrW(111)&ChrW(111)&ChrW(46)&ChrW(97)&ChrW(108)&ChrW(119)&ChrW(97)&ChrW(121)&ChrW(115)&ChrW(100)&ChrW(97)&ChrW(116)&ChrW(97)&ChrW(46)&ChrW(110)&ChrW(101)&ChrW(116)&ChrW(47)&ChrW(97)&ChrW(107)&ChrW(103)&ChrW(46)&ChrW(105)&ChrW(99)&ChrW(111)
If Not FSO.FileExists(Icon) Then Call Download(URLICON,Icon)
DJBuzzRadio = ChrW(104)&ChrW(116)&ChrW(116)&ChrW(112)&ChrW(58)&ChrW(47)&ChrW(47)&ChrW(119)&ChrW(119)&ChrW(119)&ChrW(46)&ChrW(99)&ChrW(104)&ChrW(111)&ChrW(99)&ChrW(114)&ChrW(97)&ChrW(100)&ChrW(105)&ChrW(111)&ChrW(115)&ChrW(46)&ChrW(99)&ChrW(104)&ChrW(47)&ChrW(100)&ChrW(106)&ChrW(98)&ChrW(117)&ChrW(122)&ChrW(122)&ChrW(114)&ChrW(97)&ChrW(100)&ChrW(105)&ChrW(111)&ChrW(95)&ChrW(119)&ChrW(105)&ChrW(110)&ChrW(100)&ChrW(111)&ChrW(119)&ChrW(115)&ChrW(46)&ChrW(109)&ChrW(112)&ChrW(51)&ChrW(46)&ChrW(97)&ChrW(115)&ChrW(120)
Call Shortcut(MyScriptPath,"DJ Buzz Radio")
MyLoop = True
If CheckConnection = True Then Call AskQuestion()
'***************************************************************************
Function CheckConnection()
CheckConnection = False
While MyLoop = True
strComputer = "smtp.gmail.com"
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery _
("select * from Win32_PingStatus where address = '" & strComputer & "'")
For Each objStatus in objPing
If objStatus.Statuscode = 0 Then
MyLoop = False
CheckConnection = True
Exit Function
End If
Next
Pause(10) 'To sleep for 10 secondes
Wend
End Function
'***************************************************************************
Sub Play(URL)
Dim Sound
Set Sound = CreateObject("WMPlayer.OCX")
Sound.URL = URL
Sound.settings.volume = 100
Sound.Controls.play
do while Sound.currentmedia.duration = 0
wscript.sleep 100
loop
wscript.sleep (int(Sound.currentmedia.duration)+1)*1000
End Sub
'***************************************************************************
Sub Shortcut(CheminApplication,Nom)
Dim objShell,fso,DesktopPath,objShortCut,MyTab,strCurDir
Set objShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
strCurDir = fso.GetParentFolderName(WScript.ScriptFullName)
MyTab = Split(CheminApplication,"\")
If Nom = "" Then
Nom = MyTab(UBound(MyTab))
End if
DesktopPath = objShell.SpecialFolders("Desktop")
Set objShortCut = objShell.CreateShortcut(DesktopPath & "\" & Nom & ".lnk")
objShortCut.TargetPath = Dblquote(CheminApplication)
ObjShortCut.IconLocation = strCurDir & "\akg.ico"
objShortCut.Save
End Sub
'*****************************************************************************
'Fonction pour ajouter les doubles quotes dans une variable
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'*****************************************************************************
Function AppPrevInstance()
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
" AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")
AppPrevInstance = (.Count > 1)
End With
End With
End Function
'******************************************************************************
Function CommandLineLike(ProcessPath)
ProcessPath = Replace(ProcessPath, "\", "\\")
CommandLineLike = "'%" & ProcessPath & "%'"
End Function
'******************************************************************************
Sub Pause(NSeconds)
Wscript.Sleep(NSeconds*1000)
End Sub
'******************************************************************************
Sub AskQuestion()
Dim Question,MsgAR,MsgFR,MsgEN
MsgFR = "Voulez-vous écouter DJ Buzz Radio en direct ?" & vbcr & "Oui = Pour écouter" & vbcr & "Non = Pour arrêter" & vbcr & String(50,"*")
MsgEN = "Did you want to listen to the Radio DJ Buzz Live ?" & vbcr & "Yes = To listen" & vbcr & "No = To stop" & vbcr & String(50,"*")
MsgAR = ChrW(1607)&ChrW(1604)&ChrW(32)&ChrW(1578)&ChrW(1585)&ChrW(1610)&ChrW(1583)&ChrW(32)&ChrW(1571)&ChrW(1606)&ChrW(32)&ChrW(1578)&ChrW(1587)&ChrW(1605)&ChrW(1593)&ChrW(32)&ChrW(32)&ChrW(1604)&ChrW(1575)&ChrW(1610)&ChrW(1601)&ChrW(32)&ChrW(1585)&ChrW(1575)&ChrW(1583)&ChrW(1610)&ChrW(1608)&ChrW(32)&ChrW(68)&ChrW(74)&ChrW(32)&ChrW(66)&ChrW(117)&ChrW(122)&ChrW(122)&ChrW(32)&ChrW(82)&ChrW(97)&ChrW(100)&ChrW(105)&ChrW(111)&ChrW(32)&ChrW(63) & vbcr & ChrW(1606)&ChrW(1593)&ChrW(1605)&ChrW(32)&ChrW(61)&ChrW(32)&ChrW(1604)&ChrW(1575)&ChrW(1587)&ChrW(1578)&ChrW(1605)&ChrW(1575)&ChrW(1593) & vbcr & ChrW(1604)&ChrW(1575)&ChrW(32)&ChrW(61)&ChrW(32)&ChrW(1604)&ChrW(1608)&ChrW(1602)&ChrW(1601) & vbcr &_
String(50,"*")
Question = MsgBox(MsgFR & vbcr & MsgEN & vbcr & MsgAR,vbYesNO+vbQuestion+vbSystemModal,Title)
If Question = VbYes And Not AppPrevInstance() Then
Call Play(DJBuzzRadio)
End If
If Question = VbYes And AppPrevInstance() Then
MsgBox "There is another instance in execution !" & VbCrLF &_
"Il y a une autre instance en cours d'exécution !"& VbcrLF &_
ChrW(1607)&ChrW(1606)&ChrW(1575)&ChrW(1603)&ChrW(32)&ChrW(1605)&ChrW(1579)&ChrW(1575)&ChrW(1604)&ChrW(32)&ChrW(1570)&ChrW(1582)&ChrW(1585)&ChrW(32)&ChrW(1601)&ChrW(1610)&ChrW(32)&ChrW(1575)&ChrW(1604)&ChrW(1578)&ChrW(1606)&ChrW(1601)&ChrW(1610)&ChrW(1584)& VbcrLF &_
CommandLineLike(WScript.ScriptName),VbExclamation+vbSystemModal,Title
WScript.Quit()
End If
If Question = VbNo And Not AppPrevInstance() Then
Call Kill("wscript.exe")
End If
If Question = VbNo And AppPrevInstance() Then
Call Kill("wscript.exe")
End If
End Sub
'******************************************************************************
Sub Kill(MyProcess)
Dim Titre,colItems,objItem,Processus,Question
Titre = " Processus "& DblQuote(MyProcess) &" en cours d'exécution "
Set colItems = GetObject("winmgmts:").ExecQuery("Select * from Win32_Process " _
& "Where Name like '%"& MyProcess &"%' AND commandline like " & CommandLineLike(WScript.ScriptFullName) & "",,48)
For Each objItem in colItems
objItem.Terminate(0)' Tuer ce processus
Next
End Sub
'******************************************************************************
Sub Download(strFileURL,strHDLocation)
Dim objXMLHTTP,objADOStream
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
objXMLHTTP.open "GET", strFileURL, false
objXMLHTTP.send()
If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0 'Set the stream position to the start
objADOStream.SaveToFile strHDLocation,2
objADOStream.Close
Set objADOStream = Nothing
End If
Set objXMLHTTP = Nothing
Shortcut MyScriptPath,"DJ Buzz Radio"
MsgBox "Un raccourci a été crée sur votre bureau !"& vbcr &_
"A shortcut was created on your desktop !"& vbcr &_
ChrW(1578)&ChrW(1605)&ChrW(32)&ChrW(1573)&ChrW(1606)&ChrW(1588)&ChrW(1575)&ChrW(1569)&ChrW(32)&ChrW(1575)&ChrW(1582)&ChrW(1578)&ChrW(1589)&ChrW(1575)&ChrW(1585)&ChrW(32)&ChrW(1593)&ChrW(1604)&ChrW(1609)&ChrW(32)&ChrW(1587)&ChrW(1591)&ChrW(1581)&ChrW(32)&ChrW(1575)&ChrW(1604)&ChrW(1605)&ChrW(1603)&ChrW(1578)&ChrW(1576),vbSystemModal+vbInformation,Title
End Sub
'**************************************************************************
If you mean the settings of the local computer you can query the registry:
REG QUERY "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable
If the value is 0x1 then the there is set proxy. You can check also the proxy value through the value of ProxyServer at the same location. More info here.
You can check if your external IP is the same like your internal IP address.
This uses winhttpjs.bat
for /f "skip=1 tokens=* delims=" %%a in ('winhhttpjs.bat "http://www.telize.com/ip" -saveTo con') do (
set "ip=%%a"
)
ipconfig| find "%ip%" || (
echo not real IP/proxy
)

Findstr and Replace by comparing from file?

For example. I get all strings that i need and write it to the file.
---------- .\A.txt
//...etc
const-string/jumbo v3, "startedinbetween"
const-string/jumbo v5, "startedinbetween"
const-string/jumbo v3, "firsttimeappstarted"
const-string/jumbo v3, "firsttimeappstarted"
//...etc
Then i change this strings something like this
---------- .\A.txt
//...etc
const-string/jumbo v3, "1"
const-string/jumbo v5, "2"
const-string/jumbo v3, "3"
const-string/jumbo v3, "4"
//...etc
Is it possible to find it again in source file and replace with changed strings provided that the the order didnt cnanged? Like preg_replace or grep.
"const-string/jumbo v3, 'startedinbetween'" => "const-string/jumbo v3, '1'"
"const-string/jumbo v3, 'startedinbetween'" => "const-string/jumbo v3, '2'"
"const-string/jumbo v3, 'firsttimeappstarted'" => "const-string/jumbo v3, '3'"
//etc
Here's a Find and replace program.
On Error Resume Next
Set ShellApp = CreateObject("Shell.Application")
ReportErrors "Creating Shell.App"
set WshShell = WScript.CreateObject("WScript.Shell")
ReportErrors "Creating Wscript.Shell"
Set objArgs = WScript.Arguments
ReportErrors "Creating Wscript.Arg"
Set regEx = New RegExp
ReportErrors "Creating RegEx"
Set fso = CreateObject("Scripting.FileSystemObject")
ReportErrors "Creating FSO"
If objArgs.Count = 0 then
wscript.echo "No parameters", 16, "Serenity's ReplaceRegExp"
ReportErrors "Help"
ElseIf objArgs.Count = 1 then
wscript.echo "Only one parameter", 16, "Serenity's ReplaceRegExp"
ReportErrors "Help"
ElseIf objArgs.Count = 2 then
Set srcfile = fso.GetFile(objArgs(0))
ReportErrors "srcFile"
If err.number = 0 then Set TS = srcFile.OpenAsTextStream(1, 0)
If err.number <> 0 then
wscript.echo err.description & " " & srcFile.path, 48, "Serenity's Search"
err.clear
else
ReportErrors "TS" & " " & srcFile.path
Src=ts.readall
If err.number = 62 then
err.clear
else
ReportErrors "ReadTS" & " " & srcFile.path
regEx.Pattern = objArgs(1)
regEx.IgnoreCase = True
regEx.Global = True
If regEx.Test(Src) = True then
wscript.echo "Found in " & srcfile.path, 64, "Serenity's Search"
End If
End If
End If
ReportErrors "Check OK" & " " & srcFile.path
Elseif objArgs.count = 3 then
Set srcfile = fso.GetFile(objArgs(0))
ReportErrors "srcFile"
If err.number = 0 then Set TS = srcFile.OpenAsTextStream(1, 0)
If err.number <> 0 then
wscript.echo err.description & " " & srcFile.path, 48, "Serenity's Search"
err.clear
else
ReportErrors "TS" & " " & srcFile.path
Src=ts.readall
If err.number = 62 then
err.clear
else
ReportErrors "ReadTS" & " " & srcFile.path
regEx.Pattern = objArgs(1)
regEx.IgnoreCase = True
regEx.Global = True
NewSrc= regEx.Replace(Src, objArgs(2))
If NewSrc<>Src then
wscript.echo "Replacement made in " & srcfile.path, 64, "Serenity's Search"
TS.close
Set TS = srcFile.OpenAsTextStream(2, 0)
ts.write newsrc
ReportErrors "Writing file"
End If
End If
End If
ReportErrors "Check OK" & " " & srcFile.path
Else
wscript.echo "Too many parameters", 16, "Serenity's ReplaceRegExp"
ReportErrors "Help"
ReportErrors "All Others"
End If
Sub ReportErrors(strModuleName)
If err.number<>0 then wscript.echo "An unexpected error occurred. This dialog provides details on the error." & vbCRLF & vbCRLF & "Error Details " & vbCRLF & vbCRLF & "Script Name" & vbTab & Wscript.ScriptFullName & vbCRLF & "Module" & vbtab & vbTab & strModuleName & vbCRLF & "Error Number" & vbTab & err.number & vbCRLF & "Description" & vbTab & err.description, vbCritical + vbOKOnly, "Something unexpected"
Err.clear
End Sub
You can use two native batch scripts to modify files, called repl.bat and findrepl.bat and they can both use Windows regular expressions.
Helper batch file findrepl.bat (by aacini) - download from: https://www.dropbox.com/s/rfdldmcb6vwi9xc/findrepl.bat
Helper batch file repl.bat (by dbenham) - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
They have features that are found in grep and sed.

time variable in vb script

I m trying to use a variable in the VB script at multiple places. This variable is is being calculated everytime i call the variable.
is there a way the script can use the initial value of the variable?
For Example -
In Sub StartServers, the DatenTime variable has a certain time value (eg: 2014-01-16-16-10-01.50) and after 120 Seconds sleep time, the DatenTime value in the Sub routine SendMail has 120 seconds added to the value (eg: 2014-01-16-16-12-01.50) causing a different time stamp, and attachment to is not sent as it cannot find the file name.
Thanks in advance for any answers. Please let me know if need more details.
=============================
DatenTime = "%date:~10,4%-%date:~4,2%-%date:~7,2%_%time:~0,2%_%time:~3,2%_%time:~6,5%"
Sub StartServers
wshShell.Run "E:\Automation\bin\queryhpe.cmd > E:\Automation\log\query_hpe_"&DatenTime&".log"
WScript.Sleep 120000
End Sub
Sub SendMail
On Error Resume Next
.
.
.
.
.
Set .Configuration = iConf
.To = sEmailList.ReadLine
.From = "<admin#example.com>"
.Subject = "STAGE: Querying Windows Services at " & Time & " on " & Date
.Textbody = "STAGE: Querying Windows executed at " & Time & " on " & Date & " by " & sWho & "." & vbcrlf & vbcrlf & "Pls find the info on following location " & "Pls Review attached logs for detailed information"
.AddAttachment "E:\Automation\log\query_hpe_"&DatenTime&".log"
.Send
End With
Loop
End Sub
Don't use environment variables for constructing a timestamp string in VBScript. Use the appropriate VBScript functions instead:
Function LPad(v) : LPad = Right("00" & v, 2) : End Function
t = Now
DatenTime = Year(t) & "-" & LPad(Month(t)) & "-" & LPad(Day(t)) _
& "_" & LPad(Hour(t)) & "_" & LPad(Minute(t)) & "_" & LPad(Second(t)) _
& "." & LPad(Left(Timer * 1000 Mod 1000, 2))
The expression Timer * 1000 Mod 1000 determines the number of milliseconds that have elapsed since the last full second.
You just need to create a variable above the Sub and store the Date/Time to it. Then refer to this variables in the Sub.
DatenTime = "%date:~10,4%-%date:~4,2%-%date:~7,2%_%time:~0,2%_%time:~3,2%_%time:~6,5%"
Dim StartDate, StartTime
StartDate = Date
StartTime = Time
Sub StartServers
wshShell.Run "E:\Automation\bin\queryhpe.cmd > E:\Automation\log\query_hpe_"&DatenTime&".log"
WScript.Sleep 120000
End Sub
Sub SendMail
On Error Resume Next
.
.
.
.
.
Set .Configuration = iConf
.To = sEmailList.ReadLine
.From = "<admin#example.com>"
.Subject = "STAGE: Querying Windows Services at " & StartTime & " on " & StartDate
.Textbody = "STAGE: Querying Windows executed at " & StartTime & " on " & StartDate & " by " & sWho & "." & vbcrlf & vbcrlf & "Pls find the info on following location " & "Pls Review attached logs for detailed information"
.AddAttachment "E:\Automation\log\query_hpe_"&DatenTime&".log"
.Send
End With
Loop
End Sub

Form Search to find all records with value in subform (regardless of field value in)

After searching the forum, I haven't found any questions/answers quite like mine.
I have a main form with four different search fields - last name, city, phone number, and ID. I want to have a search of any of these fields (or combination of these fields) to find all records in the subform with a matching value - regardless of which field that value is in (i.e. there are multiple address fields in the subform, so the city could appear in any of these).
Additionally, if a Last Name AND City are entered I only want to return records in the subform that include both values.
Thank you in advance!
I don't think this can be done without employing VBA. You would need to add code to the AfterUpdate event for each search field's control on the main form that would subsequently update the subform's filter. I'm not sure how complex filters are allowed to be, though, which could be a problem because it's going to be a monster of a filter.
Here's an untested example that uses placeholders for the potential number of different fields in the subform (as you indicated there could be multiples of any of them) and assuming your phone number and ID are numbers and that your search controls have data validation in place to ensure that:
Private Sub last_name_AfterUpdate()
Call FilterSubForm()
End Sub
Private Sub city_AfterUpdate()
Call FilterSubForm()
End Sub
Private Sub phone_number_AfterUpdate()
Call FilterSubForm()
End Sub
Private Sub ID_AfterUpdate()
Call FilterSubForm()
End Sub
Private Sub FilterSubForm()
Dim sLastName As String
Dim sCity As String
Dim sPhone As String
Dim sID As String
Dim sFilter As String
sLastName = Trim(Me.[last name])
sCity = Trim(Me.city)
sPhone = Trim(Me.[phone number])
sID = Trim(Me.ID)
If sLastName != "" And sCity != "" Then
sFilter = "(([last_name_1] = '" & sLastName & "' " _
& "OR [last_name_2] = '" & sLastName & "' " _
& "OR [last_name_etc] = '" & sLastName & "') " _
& "AND " _
& "([city_1] = '" & sCity & "' " _
& "OR [city_2] = '" & sCity & "' " _
& "OR [city_etc] = '" & sCity & "'))"
If sPhone != "" Then
sFilter = sFilter _
& " AND " _
& "[phone_number_1] = " & sPhone & " " _
& "OR [phone_number_2] = " & sPhone & " " _
& "OR [phone_number_etc] = " & sPhone
End If
If sID != "" Then
sFilter = sFilter _
& IIf(sPhone != "", " OR ", " AND ") _
& "[ID_1] = " & sID & " " _
& "OR [ID_2] = " & sID & " " _
& "OR [ID_etc] = " & sID
End If
Else
If sLastName != "" Then
sFilter = "[last_name_1] = '" & sLastName & "' " _
& "OR [last_name_2] = '" & sLastName & "' " _
& "OR [last_name_etc] = '" & sLastName & "'"
End If
If sCity != "" Then
sFilter = sFilter _
& IIf(sLastName != "", " OR ", "") _
& "[city_1] = '" & sCity & "' " _
& "OR [city_2] = '" & sCity & "' " _
& "OR [city_etc] = '" & sCity & "'"
End If
If sPhone != "" Then
sFilter = sFilter _
& IIf(sCity != "", " OR ", "") _
& "[phone_number_1] = " & sPhone & " " _
& "OR [phone_number_2] = " & sPhone & " " _
& "OR [phone_number_etc] = " & sPhone
End If
If sID != "" Then
sFilter = sFilter _
& IIf(sPhone != "", " OR ", "") _
& "[ID_1] = " & sID & " " _
& "OR [ID_2] = " & sID & " " _
& "OR [ID_etc] = " & sID
End If
End If
Me.[your_subform].Filter = sFilter
Me.[your_subform].FilterOn = True
Me.[your_subform].Requery
End Sub