Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Access VBA Load Control Info on form or database load

Hi

I have a table called tblAdminForms that holds information on text and images that will be loaded to when the form loads. The following code reads the table when the database loads. Is it possible to assign text to labels and images to image controls for every form and report when the database loads or should I call code on every form load event to load the controls and images

Sub loopTable()

On Error GoTo EH

    Dim strSQL As String
    Dim rs As DAO.Recordset
   
    Dim oFormOrReport As String
    Dim oControlID As String
    Dim oControlText As String
    Dim oImagePathAndName As String
   
    strSQL = "SELECT * FROM tblAdminForms"   'define the SQL result that you want to loop
    Set rs = CurrentDb.OpenRecordset(strSQL)
   
    If Not rs.BOF And Not rs.EOF Then
        rs.MoveFirst
        While (Not rs.EOF)
       
            oFormOrReport = rs.Fields("Form or Report Name")  'define the field you want to return data
            oControlID = rs.Fields("Control ID")
            oControlText = rs.Fields("Control Text")
            oImagePathAndName = rs.Fields("Image Path And Name")
           
            rs.MoveNext
        Wend
    End If
    rs.Close
    Set rs = Nothing
   
    Exit Sub
EH:
    MsgBox "Error reading tblFormsAdmin table " & Err.Description
   
End Sub
ASKER CERTIFIED SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

Thanks John. I wanted to see both your way and others so that is the answer that I needed.