Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What is wrong with my VB6? For each string in array

Posted on 2014-12-04
4
Medium Priority
?
156 Views
Last Modified: 2014-12-18
I am coding up someting that shoudl be simple. I am sure my code has an issue.

My code is below. THe issue I am having is that during the For i=0 there is an issue when inserting into the database it does not insert anything it just leaves it blank. My databasde value should be a string.

My goal is to have it run a query for each string that is in the array and use that string that it is currently on in the query.

Public pdffile As ADODB.Stream
Sub main()


    Const delimiter As String = ","

    Dim i As Integer
    Dim iterStr As String
    Dim mainlist As String
    Dim sublist As String
    Dim split_sublist() As String
    Dim pdfpath, pdfpath1 As String
    Dim sql As String
    Dim database As New ADODB.Connection
    Dim rs As ADODB.Recordset


    mainlist = AccountVariable("xrefidlist")
    sublist = AccountVariable("xrefidlist")

    split_sublist = Split(sublist, delimiter)

    For i = 0 To UBound(split_sublist)
        database.ConnectionString = "Provider=sqloledb; Data Source=192.168.2.121\EMMSDE;Initial Catalog=outlookreport; User Id=xxxxx; Password=xxxxx;"
        database.Open
        sql = "SELECT * FROM comlog"
        Set rs = New ADODB.Recordset

        rs.Open " select * from comlog", database, adOpenKeyset, adLockOptimistic
        rs.AddNew

        Set pdffile = New ADODB.Stream
        pdffile.Type = adTypeBinary
        pdffile.Open
        pdffile.LoadFromFile "C:\test.pdf"
        rs.Fields("location") = pdffile.Read
        rs.Fields("xrefid") = split_sublist(i)
        rs.Fields("sender") = "Testing VB6"
        rs.Fields("status") = "Unread"
        rs.Fields("fromemail") = "gashlin@gmail.com"
        pdffile.Close
        Set pdffile = Nothing
        rs.Update
        Set rs = Nothing

        database.Close

    Next i

    'clean mainlist the way you want.
    mainlist = Trim(mainlist)

totaloutput = Left(mainlist, Len(mainlist) -1)
AccountVariable("recievers") = totaloutput

End Sub

Open in new window

0
Comment
Question by:desiredforsome
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40481626
Move your database connection/open/close outside the loop - silly to keep opening and closing it on every iteration of the loop
Remove the SELECT - you are adding fields so no point doing a select.

Is it actually looping properly?
Have you checked split_sublist is what it should be?
Any error messages?
0
 

Author Comment

by:desiredforsome
ID: 40481729
actually it turns out my system froze up and that was the issue. HOwever, How would I go about moving my db connection outside the loop so that it can insert it freely. Would I do something like

DB.open...

Loop

After Loop

Db.close?
0
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 40481739
    database.ConnectionString = "Provider=sqloledb; Data Source=192.168.2.121\EMMSDE;Initial Catalog=outlookreport; User Id=xxxxx; Password=xxxxx;"
    database.Open

    For i = 0 To UBound(split_sublist)

        Set rs = New ADODB.Recordset
        rs.AddNew

        Set pdffile = New ADODB.Stream
        pdffile.Type = adTypeBinary
        pdffile.Open
        pdffile.LoadFromFile "C:\test.pdf"
        rs.Fields("location") = pdffile.Read
        rs.Fields("xrefid") = split_sublist(i)
        rs.Fields("sender") = "Testing VB6"
        rs.Fields("status") = "Unread"
        rs.Fields("fromemail") = "gashlin@gmail.com"
        pdffile.Close
        Set pdffile = Nothing
        rs.Update

    Next i
    Set rs = Nothing
    database.Close

Open in new window

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Introduction to Processes
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question