Results 1 to 2 of 2

Thread: Exchange data between forms : Const Expression is req.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    Exchange data between forms : Const Expression is req.

    This is a little complicated so I will try and be clear as possible. I have two forms. The first form has a drop down box that lists all the table names in my database.

    The second form opens a editable datagrid for the user to make changes to the table.

    I am able to grab the table name from the first form and pass it to the second form with this.
    Code:
        ' This is code from the first form. The table
        ' name is selected from a combobox in this 
        ' form and then passed to the second form
    
        Public Property getTableName()
            Get
                Return cboChooseTable.Text
            End Get
            Set(ByVal Value)
                cboChooseTable.Text = Value
            End Set
        End Property
    
    ---------------------------------------------------
    
        Private Sub lnkOpenTable_LinkClicked _
            (ByVal sender As System.Object, _
            ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) _
            Handles lnkOpenTable.LinkClicked
    
            ' The value is passed to the second 
            ' form named frmSqlEditor here.
    
            Dim frm1 As New frmSqlEditor
            frm1.strTableName = getTableName
            PandRControl(frm1, lnkOpenTable)
        End Sub
    Now on the second form (frmSqlEditor) this is where I am having problems. I am trying to get the table name into the constants at the top of the code like this.
    Code:
        Public Shared strTableName As String
    
        Private Const Select_String As String = _
            "Select * From " &t strTableName
    
        Private Const Connect_String As String = ( _
            "Data Source=ra04;" & _
            "Initial Catalog=Viewpoint;" & _
            "User ID=User;password=Password")
    
        Private m_DataSet As DataSet
    The strTableName has the blue squiggly under it with the message Constant Expression is required. How do I correct this? By the way the correct table name is making it from form to form because I can send it to the screen using a msgbox function.

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    You're receiving this error because a constant must resolve at compile time. What you need to do is resolve the variable at runtime. One simply solution would be to make the field readonly, which will allow you to resolve at runtime.

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