Results 1 to 16 of 16

Thread: [RESOLVED] Loading data into Combox

Threaded View

  1. #15
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Loading data into Combox

    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:
    1. '-- You had incorrectly declared the array
    2. Dim MyArray() As String, x1 As String, x2 As String
    3.  
    4. Private Sub Form_Load()
    5.     Dim cn As New ADODB.Connection, rsIndex As New ADODB.Recordset
    6.     Dim DBFullName As String, strQuery As String, strIme As String
    7.    
    8.     '-- Not the best way but a very clean way of handling your code
    9.     DBFullName = App.Path & " \Index.mdb"
    10.     cn.ConnectionString = "Provider= Microsoft.JET.OLEDB.3.51;" & "Data Source=" & DBFullName
    11.     cn.open
    12.     strQuery = "Select Ime,Prezime from StudentDetalji Order by Ime"
    13.    
    14.     rsIndex.open strQuery, cn, adOpenDynamic, adLockOptimistic
    15.  
    16.     Do Until rsIndex.EOF
    17.         '-- Like I suggested do not use space as full names
    18.         '-- can have more than once space
    19.         strIme = rsIndex("Ime") & "#" & rsIndex("Prezime")
    20.         Combo1.AddItem strIme
    21.         rsIndex.MoveNext
    22.     Loop
    23.    
    24.     '-- It is good to close the connection instead of keeping it open
    25.     '-- unnecessarily
    26.     rsIndex.Close
    27.     Set rsIndex = Nothing
    28.    
    29.     cn.Close
    30.     Set cn = Nothing
    31. End Sub
    32. Private Sub cmdBrisanjeOK_Click()
    33.     'MyArray = Split(strIme, "#") '--- Where is the value of strIme coming from????? and hence the error
    34.     'if you are picking the value from combo then try something like this in lieu of the above
    35.     MyArray = Split(Trim(Combo1.Text), "#")
    36.    
    37.     x1 = Trim(MyArray(0))
    38.     x2 = Trim(MyArray(1))
    39.    
    40.     ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    41.     '-- Open the connection once again here before performing the below action as shown above
    42.     ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    43.    
    44.     rsIndex.open "Delete from StudentDetalji where Ime = '" & x1 & "' AND Prezime= '" _
    45.     & x2 & "'", cn, adOpenDynamic, adLockOptimistic
    46.    
    47.     '''''''''''''''''''''''''''''''''''''
    48.     '-- Close connecton here
    49.     '''''''''''''''''''''''''''''''''''''
    50.    
    51.     Unload Me
    52.    
    53.     frmIndex.Show
    54. End Sub
    Last edited by Siddharth Rout; Feb 13th, 2009 at 01:40 PM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width