Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2008
    Posts
    189

    Question Unanswered: How to refer to a Table Field with a variable

    Hello,
    I have this simple code:

    Code:
    Private Sub Comando0_Click()
    
    Dim rsTablaSQLs As DAO.Recordset
    Set rsTablaSQLs = CurrentDb.OpenRecordset("tTabla SQLs para Formularios")
    
    rsTablaSQLs.AddNew
    
        rsTablaSQLs![IDFecha] = Now
        rsTablaSQLs![Nombre formulario] = Forms(Forms.Count - 1).Name
        
        Dim vQuery(50)
            vQuery(1) = "IDFecha"
            vQuery(2) = "Nombre formulario"
            vQuery(3) = "qDatos Columnas"
            vQuery(4) = "qDatos Formulario"
            vQuery(5) = "qDatos Unidades"
            vQuery(6) = "qTemp - Indicadores"
    
        For i = 3 To 6
            vSQLQuery = CurrentDb.QueryDefs(vQuery(i)).SQL
            rsTablaSQLs![vQuery(i)] = vSQLQuery
        Next i
        
    rsTablaSQLs.Update
    
    End Sub
    What I want to do is the line:
    Code:
    rsTablaSQLs![vQuery(i)] = vSQLQuery
    To change like this:
    Code:
    rsTablaSQLs![qDatos Columnas] = vSQLQuery
    rsTablaSQLs![qDatos Formulario] = vSQLQuery
    ...

    There's something wrong about how to evaluate the variable "vQuery(i)" and trying to get it as a field.

    How can I solve that?

    Thanks in advance for your help.
    Saludos,
    pepemosca

  2. #2
    Join Date
    Apr 2008
    Posts
    189

    Thumbs up

    A solution

    Code:
    Private Sub Comando0_Click()
    
    Dim rsTablaSQLs As DAO.Recordset
    Set rsTablaSQLs = CurrentDb.OpenRecordset("tTabla SQLs para Formularios")
    
    rsTablaSQLs.AddNew
    
        rsTablaSQLs![IDFecha] = Now
        rsTablaSQLs![Nombre formulario] = Forms(Forms.Count - 1).Name
        
        Dim vQuery(50)
            vQuery(1) = "ID"
            vQuery(2) = "IDFecha"
            vQuery(3) = "Nombre formulario"
            vQuery(4) = "qDatos Columnas"
            vQuery(5) = "qDatos Formulario"
        
        For i = 4 To 15
            vSQLQuery = CurrentDb.QueryDefs(vQuery(i)).SQL
            rsTablaSQLs(i - 1) = vSQLQuery
        Next i
        
    rsTablaSQLs.Update
    
    End Sub

  3. #3
    Join Date
    Apr 2008
    Posts
    189
    Is there any way to solve this by using "EVAL()"?

    Thanks!

  4. #4
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Why?

    If you have a solution without it, why bother? If you can get away without resorting to EVAL then do it imo.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  5. #5
    Join Date
    Apr 2008
    Posts
    189
    Yes, you are right. I just wanted to know how could I use the EVAL().

    But as you recomend, I'm using the index number.
    Thanks for your suggestion!!!!!

Posting Permissions

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