Okay I have cleaned your code and my comments are in green. You will now understand why the errors were happening...
Hope this helps...
vb Code:
'-- You had incorrectly declared the array Dim MyArray() As String, x1 As String, x2 As String Private Sub Form_Load() Dim cn As New ADODB.Connection, rsIndex As New ADODB.Recordset Dim DBFullName As String, strQuery As String, strIme As String '-- Not the best way but a very clean way of handling your code DBFullName = App.Path & " \Index.mdb" cn.ConnectionString = "Provider= Microsoft.JET.OLEDB.3.51;" & "Data Source=" & DBFullName cn.open strQuery = "Select Ime,Prezime from StudentDetalji Order by Ime" rsIndex.open strQuery, cn, adOpenDynamic, adLockOptimistic Do Until rsIndex.EOF '-- Like I suggested do not use space as full names '-- can have more than once space strIme = rsIndex("Ime") & "#" & rsIndex("Prezime") Combo1.AddItem strIme rsIndex.MoveNext Loop '-- It is good to close the connection instead of keeping it open '-- unnecessarily rsIndex.Close Set rsIndex = Nothing cn.Close Set cn = Nothing End Sub Private Sub cmdBrisanjeOK_Click() 'MyArray = Split(strIme, "#") '--- Where is the value of strIme coming from????? and hence the error 'if you are picking the value from combo then try something like this in lieu of the above MyArray = Split(Trim(Combo1.Text), "#") x1 = Trim(MyArray(0)) x2 = Trim(MyArray(1)) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '-- Open the connection once again here before performing the below action as shown above '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rsIndex.open "Delete from StudentDetalji where Ime = '" & x1 & "' AND Prezime= '" _ & x2 & "'", cn, adOpenDynamic, adLockOptimistic ''''''''''''''''''''''''''''''''''''' '-- Close connecton here ''''''''''''''''''''''''''''''''''''' Unload Me frmIndex.Show End Sub




Reply With Quote