Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


VB Script





VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hello All,

This is an extension of a question here - https://www.experts-exchange.com/questions/29071843/Display-Query-Results-in-Message-Box.html

I'm trying to "cache" the results of the input box and re-use it on reload of the script.

My thought is this:

Is it possible to send the result of objRecordSet("ID") to a spreadsheet, then put that result from the spreadsheet as the default data in the input box?

So, the below code works fine. It populates the fields as it should but I want to send the objRecordSet("ID") to the
spreadsheet and retrieve it from the spreadsheet at reload of the script to be input box default value - see bold font I added that's not part of the original script.

So, in effect each ID the user enters in the input box will be the default value when they re-run the script.

If there's another way to do what I'm asking, I'm all ears! I hope this makes sense, thanks!

strKey = InputBox("Enter Person ID","Search", MyDefaultValue)
If strKey = "" then
Field1 = ""
Field2 = ""
on error resume next
strConnection = "Provider=SQLOLEDB;Server=;Database=;User ID=;Password="
strSQL = "SELECT * FROM Table1 where ID LIKE '%" & strKey & "%' or User_Name LIKE '%" & strKey & "%'"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open strConnection
Set objRecordSet = CreateObject("ADODB.Recordset")
objRecordSet.Open strSQL, objConnection, adLockReadOnly
do while objRecordSet.EOF = false
Field1 = …
[Webinar On Demand] Database Backup and Recovery
LVL 11
[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Please, I have the following code and It's works fine :

strOutputFile = Left(WScript.ScriptFullName, Len(WScript.ScriptFullName) - 4) & ".csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
strLine =  """ou=Accounts,ou=Sales,ou=USA,dc=Dom,dc=local"",""DC1Serv.dom.local"""
If InStr(1, strLine, "DC=", vbTextCompare) > 0 And InStr(1, strLine, """,""", vbTextCompare) > 0 Then
             ' Search entire Active Directory domain.
            Set objRootDSE = GetObject("LDAP://RootDSE")      
            arrBits = Split(strLine, """,""")
            strOU = Mid(arrBits(0), 2)
            strDC = Left(arrBits(1), Len(arrBits(1)) - 1)
            strBase = "<LDAP://" & strDC & "/" & strOU & ">"

I want to add another OU to export the informations from two OUs of the same domain;


Please can you update the script to  export the informations from two OUs

Thank for your help;

Best regards,
how should i setup or design the VBA code wit the condition as below ?

I would need all new incoming emails (doesn't bother who is the sender) , if detected keyword (i got 5000 server name) in email body, auto categories as x(color) or y (color).
Should the code need to pointing to Excel/txt file or all 5000 keyword should import into the code ?

\\FYI, the 5000 keywords is unique.
I am having issues in VB bulk inserting text file to MDB. This is code that works at many client sites. I have resorted to testing my command in Access to make sure it is fit.

below DOES NOT WORK. the data is inserted, but only one column is created and all data goes into one column with the commas.
FROM [Text;HDR=Yes;FMT=Delimited;Database=L:\22\vbapps.2015\SnapshotOP\SSImportOP\bin\x86\Release\].recordtype1.txt;

If I move the input file to D drive, below works:
SELECT * INTO Record1short
FROM [Text;HDR=Yes;FMT=Delimited;Database=D:\].recordtype1.txt;

 I have a MS Access to duplicate current record and it is generating an error when the user clicks [Duplicate] button and I have the following VB code:

    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70

I am running Access 2013 on this computer. On other computers that are running ACCESS 2010, the [Duplicate] button works just fine.

 I checked the settings in reference (please see the screenshot posted) between this computer w/ Access 2013 and working computer w/ Acces 2010 and it is the same.

Fyi, I use the following code to open the database and set recordset to the table.

    Dim rst As Recordset
    Dim db As Database
    Set db = CurrentDb()
    Set rst = db.OpenRecordset("customer")

 What do I need to do to make it work?

Please I need a script "vbscript" to export the following attribute from two "OU" in active directory,
After to run the script we obtein a output file .csv (encode in UTF-8 )

I want to display in the output file the following fields:
"Account","Disabled","First Name","Last Name","Mail"

*Disable = True or False

Best regards,
I have a PowerShell script that collects data from Active Directory and puts it into a nicely formatted Word Document and appends the date at the end of the file name when it is saved so I can see the different files and when they were ran.
I then run the Document Merge in Word to save the file with the differences indicated between the last two times the script ran.
***I want to automate this process.***

I don't want a third party application to do this.  I want to be able to do this with either PowerShell or VBS or a VBS called out from with in a PowerShell Script.
To check health of our customized Windows appliances after Meltdown patching,
I'll need a  bat/cmd/vb (don't want Powershell) script to :

1. to list the 1st 5 lines of output (which we'll run before patch/reboot & after to compare)
2. the patch date+time  &  compare with the last reboot date/time & the date a registry
     key is added : the sequence should be  add registry key 1st, apply patch & last reboot
     date/time last

1st 5 lines:
DISPLAY_NAME: ArcSoft Connect Daemon
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
. . . . .

DISPLAY_NAME: Ac Profile Manager Service
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING

Please I need a script (vbscript or Powershell)  to export the following attribute from two "OU" in active directory,
After to run the script we obtein a output file .csv (encode in UTF-8 )

I want to display in the output file the following fields:
"Account","Disabled","First Name","Last Name","Mail"

*Disable = True or False

Best regards,
Is there a script out there (.bat or .vbs ) that verify the Meltdn/Spectr  patches are successfully applied (including that registry key is added) & the health of Windows after patching?   I don't want Powershell script.
Concerto Cloud for Software Providers & ISVs
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

I have a script that just stopped working a few days ago, when it had been working for the past three months. The script runs from a user's local drive, and only fails for a few users with a "File not found" error. Both popups are displayed, so I know both source and destination exist. The strange thing is, I added the last if statement when trying to figure out this issue, and that copy works. Has anyone ever seen this happen? What am I missing here?

set ws = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strLocalFolder = "C:\USERS\MyLocalFolder\" 

strRemoteFile = "\\ServerName\RemoteFolder\test.dat"

If (objFSO.FileExists (strRemoteFile )) Then 
	ws.Popup "Found file " & strRemoteFile 
End If

If (objFSO.FolderExists(strLocalFolder )) Then 
	ws.Popup "Found folder " & strLocalFolder 
End If

objFSO.CopyFile strRemoteFile, strLocalFolder, True

If (objFSO.FolderExists(strLocalFolder )) Then 
               objFSO.CopyFile  strRemoteFile, strLocalFolder, True
End If

Open in new window

VBScript macros based approach has been discussed previously. It worked perfectly fine by changing one line to work with .docx (office365).
I need help to run the VBScript from command line on windows machine. cscript of wscript are throwing error for declaration for FileSystemObject, String, Revision...

Please share steps to rewrite or adapt the previous solution to be able to run from command line on windows machine.

Please see the attached sample file.  The existing code works which splits out rows into separate workbooks based on an ID in column C.  Part of this code looks at specific IDs and if found groups them together and places them in new workbooks.

I am seeking assistance on modifying the code so that it also does the following:

  • Create a new workbook called JN9 if the number in column C begins with 007 and 000037 (all in one book) but excludes 007005 which should be left to run for the bulk of the primary code.  
  • Create a new workbook if the number in column C begins with 14 called IC1
  • Create a new workbook if the number in column C begins with 13 called IF1
  • Create a new workbook if the number in column C begins with 12 called S1
  • Create a new workbook if the name in column K has Franklin, Ben, Carter, Jimmy, or Clinton, Bill called Org1

These 'exceptions' should be identified first before the primary code runs so the appropriate workbooks are built.

Any assistance would be greatly appreciated.

SAPI-FULLRELEASE1.9-.vbsI need to know how to add a HTML interface to my personal assistant. Please help!
I'm using the createobject("vbscript.regexp") object in a VBA environment.  I'm getting an extra, unexpected, match that I'd like to eliminate or understand.

pattern: (.*?)($|(?:&#\d+;))
string: Now 15 & $42.0 the time;  for all good# &#34;men&#34; -2 pet the dog cat horse 1,234.56

I'm getting the expected matches (submatch tuples):
("Now 15 & $42.0 the time;  for all good# ", "&#34;")
("men", "&#34;")
(" -2 pet the dog cat horse 1,234.56", "")

as well as this unexpected match:
("", "")

Why is this happening and is there a better pattern that will eliminate this extra match?
Dear Experts,
Good day,

I am working on Reservation system, where i wrote a code if that record date gets equal to current date ... then
Just insert the same record one more time in DB, code is written below but i have a general question ....

It works fine if i stay on that page, but what if the page is not open and i would like to generate that event behind the scene.
I hope you got my idea ....
I do not want to be on the page to let that event trigger, i just want when some particular time which i will mention if arrives record inserted int DB.

I am using Asp.net VB and MS ACCESS as DB. PLS HELP

      If Convert.ToDateTime(mytxtboxdepart.Text) > Convert.ToDateTime(mytxtarrivon.Text) And mynightrun = Now.ToLocalTime.ToLongTimeString Then
                    'MsgBox(txtBoxTimer.Text & " = " & Now.ToLocalTime.ToLongTimeString)

                    Me.myAccessConnection.ConnectionString = Me.connStr
                    command.CommandText = "insert into ReservationTb([confirmid],[Gname],[ArrivalOn],[Departure],[Nights])values (confirmid,Gname,ArrivalOn,Departure,Nights)"
 end if
Screenshot: https://www.screencast.com/t/andGYDsex  notice one table is less wide than the other

The following code removes an unwanted column

                              for each trw in tbl.rows
                                    if trw.cells.count > 6 then
                                    end if

The result is randomly reducing some of the tables widths while not reducing the widths of others.
How can I make this consistent?
I have been looking, without success, for a method to log which of several DFS targets a user is mapped to at logon.  We already have a process in place that, at logon, records certain useful information to a central file share.  That info is then added to a database for reporting.  I was trying to find a way to add the connected DFS target to that info.  There is a suspected issue with some users being mapped to DFS targets outside their sites, leading to file sharing issues.
You can open a mapped drive's properties in Explorer, go to the DFS tab, and see which target path is active, but I have not found a method to do so in script or remotely.
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim cell As TableCell = e.Row.Cells(4)
            Dim cell2 As TableCell = e.Row.Cells(6)
            Dim mytxtboxdepart As TextBox = e.Row.FindControl("txtBoxDeparture")
            Dim mytxtboxstays As TextBox = e.Row.FindControl("txtBoxStays")
            Dim mytxtboxcriteria As TextBox = e.Row.FindControl("txtBoxCriteria")

            Dim provider As String
            Dim connString As String
            Dim myconnection As OleDbConnection = New OleDbConnection
            provider = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("~/App_Data/myDB.mdb")
            connString = provider
            myconnection.ConnectionString = connString

            If Convert.ToDateTime(mytxtboxdepart.Text) < Convert.ToDateTime(mytxtboxstays.Text) Then
                cell2.BackColor = Color.Red
                Dim str As String
                str = "DELETE * FROM ReservationTb WHERE Criteria" = "5"
            End If
            command.Connection = myAccessConnection
        End If
    End Sub

But i am getting the error ...
Industry Leaders: We Want Your Opinion!
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Hi there.

I have some views on my  SQL server that I show on my web application in a simple table, and I have the feature to click an Excel icon to open the output in Excel.
I do also have some dynamic queries/Stored Procedures where I don't know the number of columns. In the views above I know the columns and wrote a code like this:

<%@ Language=VBScript %>
<!--#include virtual="/includes/conxxxxxxasp" -->
dim Conn,RS1
Set Conn = Server.CreateObject("ADODB.Connection")
Set RS1 = Server.CreateObject("ADODB.RecordSet")
strConn = MM_conmcd_STRING
Conn.Open strConn 
sql1 = "SELECT var1, var2, var3, var4, var5, var6 FROM tbl_xxxxx ORDER BY var1 ASC"
RS1.Open sql1, Conn 
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=xxxx_export.xls" 
<table border="1" width="100%">
<td bgcolor="#000080"><font color="#FFFFFF">var1</font></td>
<td bgcolor="#000080"><font color="#FFFFFF">var2</font></td>
<td bgcolor="#000080"><font color="#FFFFFF">var3</font></td>
<td bgcolor="#000080"><font color="#FFFFFF">var4</font></td>
<td bgcolor="#000080"><font color="#FFFFFF">var5</font></td>
<td bgcolor="#000080"><font color="#FFFFFF">var6</font></td>
<%Do While Not RS1.eof%>
Set Conn = 

Open in new window

Dear Experts,
I hope i will get the answers of my question by today ..
I am working on Hospitality Management Software, of which 70% is done only Billing Section's few part left .. and thats where i am stuck. I am using Asp.net VB & MS Access as back-end.
My Requirement i would like to take a value when a NEW RESERVATION will be made "Arrival on" to "Departure"
Right now i just can save 2 values which is Arrival date & Departure date in database but i want something like this as below ...
so what i need i am giving you idea in DB actually how it goes ....

id    confirmid   name     arrivalon     departure         currentdate
1      1111           ABC       01/3/2018   01/05/2018       01/3/2018
2      1111           ABC       01/3/2018   01/05/2018       01/4/2018
3     1111           ABC       01/3/2018   01/05/2018       01/5/2018   ------> if this equals departure date ABC  CHECK OUT
4      2222           XYZ        01/3/2018   01/04/2018       01/3/2018
5      2222           XYZ        01/3/2018   01/04/2018       01/4/2018    ------> if this equals departure date XYZ CHECK OUT

so my problem is i just can save arrival on & departure first row which is id 1, the remaining id 2 & & 3 how can i save,
Similarly id 4 is saved when i make a new reservation the id 5 how can i save.

I had this question after viewing "More than One Message or Notes Control" error in VBA when creating Outlook mail item..

I am seeing the same issue as the previous OP, although I do not always get the error. I am creating a new mail item (with an attachment). Up until a month ago it worked 100% of the time. Now it works about 75% of the time, I cannot figure out how to replicate the issue, i.e. it seems random. 25% of the time, the email displays with an additional set of buttons and textboxes, and when this happens none of the buttons, or text fields can be mouse selected. I can work around it by closing the email (save as draft) and than opening it from the 'drafts' folder, this workaround works 100% (so far). This behavior has never happened when just creating a new email from within Outlook, only when the VB app creates the email.
Outlook FailAs far as the error goes, I only get that about half of the times that the email displays/behaves wonky... and never when it displays/behaves correctly. The message simply says: "This form has more than one Message or Notes control. If more than one control is visible at run time, only one control works."
Outlook WarningHere is a code snippet for the new mail bit...
        Dim Outl As Interop.Outlook._Application
        Outl = New 

Open in new window

objCommand.ActiveConnection = objConnection                              'assignment to an existing ADO connection
        objCommand.Properties("Page Size").Value = 1000                          'set the Paged Results value to 1000 (AD standard)
        objCommand.Properties("Cache Results").Value = False


        objRecordSet.CacheSize = 500
        objRecordSet.PageSize = 1000

Or Both
I'm creating a service website using visual studio 2015 and VB web form site, I need the user to select a date to book in for a service using calendar control and for that date to be put into car service date field in the database which is NULL at the moment,  how would I go about doing this, I'm struggling because I'm new to VB and many website tutorials cover c# for this particular question.
I have written a VBA function in MS Outlook that takes about 30 seconds to run. It needs to open and read data in a spreadsheet as well as loop through emails. I need the application to run every 30 minutes or so to see if there have been any new emails arrive or any updates to the spreadsheet. The trouble is that if I am using MS Outlook at the time it will interrupt and make me wait so I was wondering if there is a way to run it without interfering.

I was thinking that perhaps it may be possible to create an instance of Outlook and Excel using VB Script or perhaps running it from another MS product that I don't use very often like Publisher or Powerpoint, or perhaps I should create a virtual machine and leave an instance of Publisher running on it (though that will likely be very resource hungry). I don't think this is a new problem so I am hoping someone has a relatively straightforward suggestion.

VB Script





VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.