Link to home
Start Free TrialLog in
Avatar of jxharding
jxharding

asked on

imagebox array loses index, possibly declare connectionstring globally

i am using vb6sp5, and an access database to get strings for the pictures on the imageboxes

i have an array of imageboxes
on the click event, the index is called:

Private Sub imgPicture_Click(Index As Integer)

however i can click on say img1,then img2, then img3
and the indexes are called fine , namely, 1,2,3 respectively

then when i click on img1 for example again, the index is set to 0
this happens when i click on imageX, imageY and imageX again.
and i get an "unspecified error" the debugger stops on my connection string

 oconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
               "Data Source=.\tapeus.mdb;" & _
               "User ID=admin;" & _
               "Password=;"
               
which is working fine, because i just connected to it twice.

maybe its the connection that does not like to be reconnected so much, how can i the connectionstring
public so i only need to connect once, i cant put it in general declaration
i am currently declaring it in every sub or function


ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jxharding
jxharding

ASKER

Hi Tim

heres my sub main module, which is set as start up:

(general declaration)
  Public oConn As ADODB.Connection

Public Sub Main()
   Set oConn = New ADODB.Connection
  oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=.\tapeus.mdb;" & _
           "User ID=admin;" & _
           "Password=;"
  oConn.Open
  Form1.Show vbModal
End Sub

then it goes straight to form_load,which contains only
    Dim SQLQ As String
    SQLQ = "SELECT * FROM Products"
    rsProductsG.Open SQLQ, oConn, adOpenStatic, adLockBatchOptimistic, adCmdText

but when i reach this , oconn = nothing
and i get an "object required " message