Ask a questionAsk a question
 

Questionsql code to display a particular field

  • Sunday, November 01, 2009 3:47 AMLEE CL Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I created a table (named: tbl_x) using microsoft access 2003
    tbl_x contains n fields; namely fld_1, fld_2, .... fld_n.
    I wrote a code to a recordset as follows:
    ---------------------------------------------------
    Function disp_field()
    'declare variables
    Dim var_fieldname as fields, rst as recordsets
    var_fieldname = Inputbox("Key in the field name.")
    sqltxt = " Select tbl_x.var_fieldname FROM tbl_x;"
    Set rst = CurrentDb.OpenRecordset(sqltxt)
    rst.MoveLast
    rst.MoveFirst
    x = rst.RecordCount
    MsgBox "The field contains " & x & " records."

    End Function
    -------------------------------
    When run, the error msg is:

    Runtime error 91
    Object varialbe or With block variable not set


    Please help. Thx.