Access VBA

css navigation by Css3Menu.com

Populate Unbound Form from Recordset

Our computer group was doing a charity event called Coders 4 Charities. My team's client had asked that a form be changed to have a SAVE button.

They we needed the flip side; to populate the Unbound fields with the current data.

Private Sub Combo54_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs          As Object
    Dim myTable     As DAO.Recordset
    Set rs = Me.Recordset.Clone
    rs.FindFirst "[EmployeeID] = '" & Me![Combo54] & "'"
'    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
'=======================
Set myTable = CurrentDb.OpenRecordset("SELECT * from tbl_Employees WHERE " _ & " [EmployeeID] = '" & Me.Combo54.Value & "'") Me.EmployeeID = myTable![EmployeeID] ' Table items Me.FName = myTable![FName] Me.LName = myTable![LName] If myTable![Active] = False Then Me.Active = 0 Else Me.Active = -1 End If If myTable![sex] = 2 Then Me.Frame70.Value = False Else Me.Frame70.Value = True End If Me.DeptLocation = myTable![DeptLocation] Me.JobTitle.Value = myTable![JobTitle] Me.MainAddress = UCase(myTable![MainAddress]) Me.MainCity = UCase(myTable![MainCity]) Me.MainState = UCase(myTable![MainState]) Me.MainZip = myTable![MainZip] Me.MainCounty.Value = myTable![MainCounty] Me.PhHome = myTable![PhHome] Me.PhMobile = myTable![PhMobile] Me.PhOther = myTable![PhOther] Me.SSN = myTable![SSN] Me.PreTraining = myTable![PreTraining] Me.BirthDate = myTable![BirthDate] Me.DateHired = myTable![DateHired] Me.DateLeft = myTable![DateLeft] Me.Reason = UCase(myTable![Reason]) Me.Frame70.Value = myTable![sex] Me.EmgContact = UCase(myTable![EmgContact]) Me.EmgRelation.Value = myTable![EmgRelation] Me.EmgPhone = myTable![EmgPhone] Me.EmgMobile = myTable![EmgMobile] Me.EmgOther = myTable![EmgOther] myTable.Close ' Close to release memory Set myTable = Nothing Set rs = Nothing '============================ End Sub

You know the hell you go through when you cannot remeber the syntax for something. Imagione how we felt sitting there searching the web, remembering that we only had 2 days to complete all their changes.

© 2009-2024

Updated:  06/21/2024 07:42
This page added:  17 October 2009