Results 1 to 2 of 2

Thread: The eval method - any alternatives?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    11

    Hi,
    I have a function which receives a control name (as a a string) within the function parameter. I wish to use that string name and use the additem to add data to that name.

    I thought it was possible with the Eval method I have come across before in MS Access. However, I have had no luck in my version of VB6 Enterprise (SP4). I get errors trying to use the Eval method. Is there an alternative to his, or is my code structured wrong.

    Any help much appreciated,

    Russ

    My code looks like this:

    Private Function PopulateBox(RS As ADODB.Recordset, str As String) As Boolean

    If RS.RecordCount = 0 Then
    PopulateBox = False
    Else
    Do Until RS.EOF = True
    ' NEXT LINE DOESN'T WORK!!!
    eval(str & ".AddItem " & RS!Desc)
    RS.MoveNext
    Loop
    PopulateBox = True
    End If

    End Function

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Pass the control in as its correct type, or as a control type. That should sort out your problems.

    Code:
    Private Function PopulateBox(RS As ADODB.Recordset, myCtrl As Control) As Boolean
    
      If RS.RecordCount = 0 Then
        PopulateBox = False
      Else
        Do Until RS.EOF = True
    
          myCtrl.AddItem RS!Desc
    ''      eval (str & ".AddItem " & RS!Desc)
          RS.MoveNext
        Loop
        PopulateBox = True
      End If
    
    End Function
    Iain, thats with an i by the way!

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