Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    santa clara

    Unanswered: How to populate a textbox with data

    I'm trying to populate a simple textbox with data from a table.

    The table holds some constants like median_wage, avg_repair, etc... how can i populate say the wage in a text box so i can use it in a formula on my form?

    Here's what i'm doing right now... in my textbox i have on the data tab of the textbox... in the control source =Constants_q!medain_wage. but when i open the form it says #Name?

    What is that about?

    Thanks for any help.



  2. #2
    Join Date
    Jan 2005
    you can set your text box by calling this function. if you want to fetch a different constant from you table just change the ("AveWage")

    put this in your form's class module:

    Private Sub Form_Open(Cancel As Integer)
    Me!txtAveWage = GetConstant("AveWage")
    End Sub

    then put this in a public module:

    Public Function GetConstant(item As String)
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim strSQL As String
    Set db = CurrentDb
    strSQL = "SELECT val FROM constants WHERE item = '" & item & "';"
    Set rst = db.OpenRecordset(strSQL)
    GetConstant = rst!Val
    End Function

    hope this helps

Posting Permissions

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