Search code examples
ms-accessvbams-access-2007subform

MS Access 2007 Converting forms into sub form - "form not found" issue


So I recently have been trying to incorporate more sub forms to make the UI more friendly. So I have a pre developed form that runs some VB, so for examples sake lets just say that it runs SQL statement, returns the recordset, and fills text boxes with the data (because this is sort of an interactive dashboard concept:

dim db as database
dim rs as recordset
dim sql as string
set db = current db

sql = "SELECT * FROM tblMain;"

   set rs = db.OpenRecordSet(sql)

         rs.movefirst
             [forms]![DashboardSubName].txtValue1 = rs!Value1
         rs.close

 set rs = nothing
 set db = nothing

with error handling that returns a error "DashboardSubName" not found. So orginally this form was its own form, and opening it by itself it works fine, but once I use it within the parent form i get this error.

im sure it is simply something i am not aware of, but what gives?

thanks guys justin


Solution

  • Assuming the code you showed us is part of the subform, rather than the parent form, replace

    [forms]![DashboardSubName].txtValue1 = rs!Value1
    

    with

    Me.txtValue1 = rs!Value1