Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    TreeView from a table (2003)

    I try to use a table to generate a treeview object and I have the code below on the NodeClick event. This code generate two errors
    1.- The line rst1.Open strSQL, cnn, adOpenStatic, adLockOptimistic, adCmdText generates a run time error with the message "No value given for one or more requires parameters. If I take of the where part it runs fine. So my 1st question what is wrong with the Where clause?
    2.- The line DoCmd.OpenForm strForm, varOpenForm generates a type mismatch error due to the variable VarOpenForm, so the question is how can I use a variable to define the form view.

    I have attached an Excel file with the tbltvw table and a copy of the form with the tree view object.

    regards,
    Marcel

    Private Sub tvw_NodeClick(ByVal Node As Object)

    Dim cnn As ADODB.Connection
    Dim rst1 As ADODB.Recordset
    Dim strForm As String
    Dim varOpenForm As Variant
    Dim strSQL As String
    Dim strNode As String
    Dim strFilter As String

    Set cnn = CurrentProject.Connection
    Set rst1 = New ADODB.Recordset

    strNode = Node.Key

    strSQL = "SELECT tbltvw.* FROM tbltvw WHERE tbltvw.NodeCode= strNode"

    rst1.Open strSQL, cnn, adOpenStatic, adLockOptimistic, adCmdText

    If Not (rst1.EOF) Then
    strForm = rst1!FormName
    varOpenForm = rst1!FormOpenType
    DoCmd.OpenForm strForm, varOpenForm
    End If

    End Sub

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TreeView from a table (2003)

    1. To pass the value of strNode to the where condition change the strSql line to :
    <pre>strSQL = "SELECT tbltvw.* FROM tbltvw WHERE tbltvw.NodeCode= '" & strNode & "'"</pre>

    2. What are you trying with the second argument (varOpenForm) in the line :
    DoCmd.OpenForm strForm, varOpenForm
    These argument can only be 0, 1, 2 or 3 or the equivalent constants acNormal, acDesign, acPreview or acFormDs
    Is this what varOpenForm contains ?
    Francois

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: TreeView from a table (2003)

    Are you trying to do this in Access or Excel? The Excel file is not very helpful, since it merely includes a picture of the form, not a functional object. However, I suspect that your problem is in this line:

    <code>
    strSQL = "SELECT tbltvw.* FROM tbltvw WHERE tbltvw.NodeCode= strNode"</code>

    Try changing it to this:


    <code>strSQL = "SELECT tbltvw.* FROM tbltvw WHERE tbltvw.NodeCode= '" & strNode & "'"</code>

    In the original code, you are specifying a literal value "strNode" in the SQL, not the value currently assigned to that variable.
    Charlotte

  4. #4
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TreeView from a table (2003)

    thank you it works fine now. I have change the strSQL string.
    Concerning the varOpenForm variable, I have changed the data in the table to have the number 0,1,2 or 3 instead to have the equivalent constant acNormal, acDesign....
    regards,
    Marcel

  5. #5
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TreeView from a table (2003)

    The Excel file was just as information with a copy of the table and a screen copy of the form with the treeview.
    Anyway thank you for your help, the recordset works fine with the change in the strSQL that you and francois proposed.
    Regards,
    Marcel

Posting Permissions

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