Visual Basic Classic

163K

Solutions

43

Articles & Videos

58K

Contributors

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

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

Sign up to Post

Hello!

I am writing a VB6 program to read an XML file.  The XML has encoding="UTF-8".

I have everything working with the exception of the embedded attachments.  There is a file name (jpg, doc, etc.) which I can pick up.  My problem is that the data element is just a bunch of characters.  Somehow I need to take the group of characters and convert it to a jpg or doc file.  

Does anybody know if this is possible,  and if so,  how is it done?

Thanks for your help!
0
Independent Software Vendors: We Want Your Opinion
Independent Software Vendors: 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 Experts,

I had this code working fine in a DSN based connection.
Set objRec = CreateObject("ADODB.Recordset")
Set objConn = CreateObject("ADODB.Connection")

objConn.ConnectionString = "Provider=MSDASQL;DSN=PlacementNP;Initial Catalog=PlacementNP;User Id=MyUser;Password=MyPWD"
objConn.Open

Open in new window


However now that we changed to a DSN-less connection I can't get it to work, tried the following
Set objRec = CreateObject("ADODB.Recordset")
Set objConn = CreateObject("ADODB.Connection")

objConn.ConnectionString = "ODBC;DRIVER=sql server;Server=tcp:sqlserver1\exp08;Database=PlacementNP;UId=MyUser;PWD=MyPWD;Trusted_Connection=No"
objConn.Open

Open in new window

And I get the attached error, when all the credentials are still the same.

Any idea what's wrong here?
Untitled.png
0
So, I have to look through a worksheet and identify where groups of numbers match.

Could someone help me with code which will do this for me please ?

Also, would it be possible to identify each matching group of number with their own colour ?

I have attached a worksheet to illustrate


thanks
006-triplet-duplicate-id-EE.xls
0
Hello,

How do you modify Excel VBA macro code (containing a keyboard timestamp shortcut) so that, each time the macro is invoked, it reproduces the actual shortcut keystrokes (and therefore the current time) rather than the "absolute" time value the shortcut produced when the macro was originally recorded?

After clicking to Use Relative References (ie Developer > Use Relative References), the Excel macro recorder was used and created the following code:

Sub Macro12()
'
' Macro12 Macro
'

'
    Application.Goto Reference:="DateEnd"
    ActiveCell.Offset(0, 2).Range("A1").Select
    Selection.End(xlUp).Select
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveCell.FormulaR1C1 = "11:59:00 AM"
    ActiveCell.Offset(0, 3).Range("A1").Select
End Sub

Open in new window

The relative actions (keystrokes) appear to have been recorded properly except for the following row:
       
ActiveCell.FormulaR1C1 = "11:59:00 AM"

Open in new window

At this particular part of the recording, the shortcut [Ctrl+Shift+;] was used to enter the current time. As is shown above, the time when the macro was being recorded was apparently 11:59 AM. However now, each time the macro is run, it does not enter the current time as it should but enters 11:59 AM.

So how must that row of code be modified so that each time the macro is run in the future, it will reproduce the keystrokes shortcut and post the current time then instead of always entering 11:59 AM?

By the way, I …
0
After this code runs and adds a record to the recordset, I am unable to add any more entries into the record. I believe the record is getting locked by the database since it detected changes, but I'm not sure how to remove that through access. I have verified this code works properly besides the unintended side effect of being unable to repeatedly do it. Does anyone know how to unlock the record so everyone can access it after this runs?

This is a copy of the entire code segment.
2017_06_20_11_16_43_Microsoft_Visual.png
This is the error message received after it SUCCESSFULLY updates the record the first time.
2017_06_19_12_44_48_Microsoft_Visual.png
This is the debug line that reports the database error.
2017_06_19_12_48_50_Microsoft_Visual.png
Things I've tried to get it to work.
-Adding a ClientRS.Edit before the arguments.
-Removing the ClientRS.Close

Things to note
-This is a seperate form that adds a phone number to a table of phone numbers with a Company ID, Company Name, etc.
-The data is managed by an SQL database that Access links to.
0
After this code runs and adds a record to the recordset, I am unable to add any more entries into the record. I believe the record is getting locked by the database since it detected changes, but I'm not sure how to remove that through access. I have verified this code works properly besides the unintended side effect of being unable to repeatedly do it. Does anyone know how to unlock the record so everyone can access it after this runs?

    Set ClientRS = CurrentDb.OpenRecordset("Client Contacts", dbOpenDynaset, dbSeeChanges)
   
    With ClientRS
        .AddNew
        ![id] = ClientID
        ![Full Name] = FullName
        ![Phone Number] = PhoneNumber.Value
        ![Company] = "Other"
        .Update
        .Close
    End With

    Set ClientRS = Nothing
   
    DoCmd.Close acForm, "Add Phone Record", acSavePrompt
End Sub
0
Hi Experts,

I'm getting the attached error on the following line
    Dim mrstZipCodes As ADODB.Recordset
    Set mrstZipCodes = CurrentProject.Connection.Execute("SELECT * FROM tblZipCodes WHERE ZipCode = '" & strZipSearch & "'")

Open in new window

This is something that previously worked well, and in fact its still working in others pc's, however its stopped working at one pc, any idea how to make that work again?

I compared the references with the other working pc and both have the same, see attached(2).

PS. This pc has A2007 and we tried installing the runtime of a later version and then we un-installed it.

Thanks in advance
Untitled.png
Untitled.png
0
I have rows of data, from which I need to sort into every possible combination of three (as per worksheet)

I think there are 18 or 20 possible combinations altogether, I have done half a dozen for illustration.

Could someone help me with code that will sort thousands of rows into this format please ?


thanks

006-triplet-studies-EE-sample.xls
0
experts,

I inherited an Access database with the following

Its a split database with a Master Table with say 500 records. When we edit a record, theres a form of unbound fields that create filter criteria, and then runs a make table query to Table 1. Then opens Form 1 that is bound to Table 1 and displays just the records to be viewed.

I was given a requirement to lock and disable every control on Form 1, and add a command button to open a duplicate Form 2 that is editable, to make it more difficult for users to accidentally alter data.

The user then makes changes to a record and submits the changes via command button which updates the master table, an audit table, etc. and closes the editable version if the form.

At this point, i want to requery Form 1 to show the updated record, which means i have to run a Make Table query to update Table 1. Of course, at this step, the fails and notifies me that Access cannot lock Table 1 because it is being used.

But, even if i close Forms 1 and 2, essentially all open forms bound to Table 1, it continues to stay locked so i cant update it and i dont understand why.

Anyone know why?
0
Respected All,

Hope you are all Fine i have recorded a macro with vlookup formula it comes in R1C1 format Please advice how to make Criteria Range Which is (Sheet1!R[-57]C[-5]:R[186]C[17] = B1:S244)  Dynamic so that if some data Added in last row which will be 245 it Will auto include in range.

Sub VlookupExtractRecoveries()

'Code to Apply Vloockup Formula to Extract Figures in Recovery Report
Dim LR As Long
LR = Range("G58").End(xlDown).Row

    Range("G58").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(VLOOKUP(RC[-5],Sheet1!R[-57]C[-5]:R[186]C[17],COLUMNS(Sheet1!R[152]C[-5]:R[152]C[10]),0),0)"
    Range("G58").Select
    Selection.AutoFill Destination:=Range("G58:G" & LR), Type:=xlFillDefault
  Range("G58").Select
 
  'Code to Convert Formula as Peste Special value
 
    Range(Selection, Selection.End(xlDown).Offset(-1)).Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        'Code for Esc Copy Cut or Cancel Sellectoion
        Application.CutCopyMode = False
End Sub
0
Enroll in June's Course of the Month
LVL 9
Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Hi I am trying to extract the value from form objects such as Listboxes, comboboxes, textboxes and the like that are on a form.

I have no issue when each is individually named but when I attempt to use an array of say a textbox I run into difficulties.

Two textboxes with name txtfields index 0 and 1 created on form.

Dim I as integerError MessageDim ctl as string

 For i = 0 To 1
     
     If i = 0 Then
         ctl = "txtFields(0)"
       Else
         ctl = "txtFields(1)"
     End If
       
     Debug.Print "Test: ", Me.Controls(ctl).Text
   
    Next
   

I have tried various assignments such as ctl = "txtfields" & ibut still get the same error.

Any assistance would be appreciated.

Thank you.

Edward
0
I want to send sms from vb6 application. I have third party tool. He has given http://mobile.sendsms.com/api/smsapi.aspx?username=abcd&password=abcd&to=MOBILENO&from=fromhdr&message=this is test sms


following command i have written in vb6 code but it is not working.

TextString= "http://mobile.sendsms.com/api/smsapi.aspx?username=abcd&password=abcd&to=MOBILENO&from=fromhdr&message=this is test sms"
   
    Open "c:\SmsSend1.Bat" For Output As #1
    Print #1, TextString
    Close #1
    Shell "C:\SmsSend1.Bat", vbHide



in vb6 how to execute this command in vb6. I want to execute this command after saving data record.


Thanks
0
I have set up a basic working website and can print out Hello World in htm.
I have also installed PHP and registered new PHP version.
 In Sites/Default Web Site the path is c:/webapps/BVC.

How do I make localhost the default and is there any more set up required to run PHP ?

Michael
0
I'm trying to create a .txt file with UTF8 encoding, the script below works but does not product an UTF8 encoded file:


     
            Dim fs As Object

    Dim stream As Object

     
    Set fs = CreateObject("Scripting.FileSystemObject")

    On Error GoTo fileexists

        Set stream = fs.CreateTextFile(DEMFolder2.SelectedItems(1) & "\" & DEMFolderString & "\1. Load Files\" & DEMNumber & ".txt", False, True)


fileexists:

        If Err.Number = 58 Then

            MsgBox "File already Exists"


        Else

            stream.Write ("DEM Claim Number=" & DEMNo)
            stream.WriteLine
            stream.Write ("RECORDING match file name=" & CMFilename & ".csv")
            stream.WriteLine
            stream.Write ("MEMBER match file name=" & MIDFilename & ".csv")
            stream.WriteLine
            stream.Write ("PERFORMER match file name=" & PIDFilename & ".csv")
            stream.WriteLine
            stream.Write ("Performer Single/Multiple Role [S/M]=S")
            stream.WriteLine
            stream.Write ("Collecting Society=" & Soc)
            stream.WriteLine
            stream.Write ("New Society [Y/N]=" & NewSoc)
            stream.WriteLine
            stream.Write ("Country=" & Country)
            stream.WriteLine
            stream.Write ("Description=" & DEMDescription)
            stream.WriteLine
            stream.Write ("Distribution Start Year=" & AirStart)
            stream.WriteLine…
0
Experts,

if i develop an Access database between two machines, one running Access 2013 and the other running Access 2016, could that cause unexpected behavior in my VBA code when testing it on the machine running 2013?

Ive had a number of instances where i had to rewrite code that worked for awhile and then failed. For example,

Today, i passed the integer 3 as a parameter x to a sub, and the statement:
If x = 1 or 2 Then
   (do something for options 1 or 2)
Else (do something for option 3)
End If

When i stepped through the code, i could see that x = 3 in the locals window, but it still behaved as if x was 1 or 2. I had to rewrite the If statement as
If x <=2 Then

and then it behaved as expected.

What would cause this?
0
I have vb6 application thru which i am able send report  as PDF document as mail attachment. I want to include password for pdf file. Following is coding. How can i set password for PDF documents.

repSaleRegister  is report generated by crystal report designer in vb6 application.

Thanks
   
    repSaleRegister.ExportOptions.Reset
    repSaleRegister.ExportOptions.DestinationType = crEDTEMailMAPI
    repSaleRegister.ExportOptions.FormatType = crEFTPortableDocFormat
    repSaleRegister.ExportOptions.MailToList = adoTR_EMPAYDATRs.Fields!PMEMAIL
    repSaleRegister.ExportOptions.MailSubject = "Test Report"
    repSaleRegister.ExportOptions.PDFExportAllPages = True
    repSaleRegister.ExportOptions.FormatType = crEFTPortableDocFormat
    repSaleRegister.ExportOptions.MailMessage = "Dear  Please find attached report"
    repSaleRegister.Export False

Open in new window

0
Hi,

Can someone please help me with combining both the function together.

VLOOKUP(U3,Sheet2!C:D,2,0)  and =IF(T3<$P$1,"Yes",IF(T3>$P$1,"No"))

if vlookup gives #NA than IF function applies

Thanks alot.
0
Hi guys,

I'm trying to send mail from EXcel with an attachment, but its not working for me.... Line 39 is not working
Sub CreateEmail()

        Const EMBED_ATTACHMENT As Long = 1454

        Dim Notes As Object
        Dim Maildb As Object
        Dim objNotesDocument As Object
        Dim objNotesField As Object
        Dim Attachment As Object
        
        Dim stSubject As String
        Dim stBody As String
        Dim vaRecipients As String
        
        
    
        vaRecipients = "xxx@yyy.dk"
        stSubject = "Subject title " & Format(Now(), "mm-yyyy")
        stBody = "lalalala"
        stAttachment = "C:\Test\test.txt"
        

        Set Notes = CreateObject("Notes.NotesSession")
        Set Maildb = Notes.GETDATABASE("", "")
        Maildb.OPENMAIL
        Set objNotesDocument = Maildb.CREATEDOCUMENT

        Set objNotesField = objNotesDocument.APPENDITEMVALUE("SendTo", vaRecipients)
        Set objNotesField = objNotesDocument.APPENDITEMVALUE("Subject", stSubject)
        Set objNotesField = objNotesDocument.APPENDITEMVALUE("SaveMessageOnSend", True)
        Set objNotesField = objNotesDocument.APPENDITEMVALUE("PostedDate", Now())
        Set objNotesField = objNotesDocument.APPENDITEMVALUE(EMBED_ATTACHMENT, "", stAttachment, "")
        
        Set workspace = CreateObject("Notes.NotesUIWorkspace")
        Call workspace.EDITDOCUMENT(True, objNotesDocument)
        Set uidocument = workspace.CurrentDocument
        Call 

Open in new window

0
xRef-jobs_boqs---SEARCH-FORM-1.0.xlsxxRef-jobs_boqs---SEARCH-FORM-1.0.xlsxhi experts id like a simple excel form to be created as per my attached excel workbook, if you need any other info please ask..
0
Salesforce Made Easy to Use
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

My Questions:  1. How do I expose all active code (macros, Active X, etc) inside of a Word document (.doc) to analyze it?

2. What does the ClamV virus detection signature "Sanesecurity.Badmacro.Doc.vbh.UNOFFICIAL" indicate?

Why I ask:  Two Word documents (.doc) were blocked by our mail scanner with definition "Sanesecurity.Badmacro.Doc.vbh.UNOFFICIAL" (screenshot attached).  I ran them through VirusTotal for a second opinion, nothing was detected.  When I opened the Word documents on an isolated computer, I enabled active content to try to view the macro code.  There was hardly any code in there, and I wonder if I missed something.  

In document number one, the only code is "Private Sub Document Document_New ()" on one line, then "End Sub" on the other line.

In document number two, the only code is "Private Sub tts_OnReadyStateChange (ByVal newState As Long)" on one line, then "End Sub" on the other line.  

As far as I can tell, this code does nothing.

Am I missing code that could be buried somewhere else?
Sane-Security.JPG
0
Hi All,
i have a question in here about if currently i have 3 test box and all 3 is use to scan in barcode, we name it text1, text 2 and text 3. firstly i need to scan barcode in text box 1, but after i scan the barcode in text box 1 and immediately the focus point will go to text box 2, then the same step for text box 2 after scan will go to text box 3, and finally when scan barcode to text box 3 the program will do some comparison.

Any one have an idea please

Regards
Steve
0
how can conver native code to vb 6.0 source code
0
Dear Experts:

i need an VBA to create list of Worksheets based on  cell "A31" from Sheet 120 and cell "A29" from Sheet 121. If "Reporting Population: Non-Charged Off Accounts" exist in worksheet then add to the list in "Sheet3".
Please not that i have 121 sheets, i added two sheet for example.


Help is much appreciated.

Thank you very much in advance.

Regards, Bir NA
Book1.xlsx
0
Is there VBA code that will convert a mapped file path to a UNC?

Example:

P:\folder 1\myFile.xlsx  

....converts to....

\\server1\group\Public\folder 1\myFile.xlsx
0
I have this Macro that works great but I would like to add....
...the condition to delete the column if each cell in the column is empty

Sub RemoveDupCols()
    Application.ScreenUpdating = False
    lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
    For i = lastCol To 1 Step -1
        LastRow = Cells(Rows.Count, getColName(i)).End(xlUp).Row
        uniqueCount = CountUnique(ActiveSheet.Range(getColName(i) & "$2:" & getColName(i) & "$" & LastRow))
        Debug.Print "Column " & getColName(i) & "'s unique values count:" & uniqueCount
        If uniqueCount = 1 Then
            Columns(getColName(i)).Delete Shift:=xlToLeft
        End If
    Next
    Application.ScreenUpdating = True
End Sub

Public Function CountUnique(rng As Range) As Long
    Dim dict As Object
    Dim cell As Range
    Set dict = CreateObject("Scripting.Dictionary")
    For Each cell In rng.Cells
         If Not dict.Exists(cell.Value) Then
            dict.Add cell.Value, 0
        End If
    Next
    CountUnique = dict.Count
End Function

Public Function getColName(ByVal colN As Integer) As String
    getColName = Left(Cells(1, colN).Address, Len(Cells(1, colN).Address) - 2)
End Function

Open in new window


For example, these empty columns were left behind:2017-05-18_1102.png
Thank you.
0

Visual Basic Classic

163K

Solutions

43

Articles & Videos

58K

Contributors

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.