AccessDiscussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
There are a combo box and button âCreateâ on Form_1. Clicking on the button, the Form_2 which is used to create a new record is opened. After a new record is entered, the Form_2 is closed.
Problem: The new record just entered cannot be found in the combo box of Form_1. It will show there only after closing/reopening Form_1
How to make it without closing/reopening the form?
I got around this problem another way. I have two forms that I switch back and forth between to enter new records. The buttons that I use to open the new form has this line before the code to open the new form:
DoCmd.Close
Then when the record is added in the second form, the button to go back does the same thing. This automatically requeries the opening form, of course.
This assumes you want to click a button each time. But I find it keeps the work area less cluttered having only one form open at a time.
After creating the new record in Form-2, close the form by clicking on button click. The key field of the new record is added in the combo box in Form-1. How to set the new one to be selected in combo box and display data of other fields in form-1 automatically?
I add the following codes in form-2
Private Sub newClsClose_Click()
Forms![Form-1].Requery
Forms![Form-1].[cbx].Requery 'combo box requery
'Find the record that matches the control
Dim rs As DAO.Recordset
Set rs = Forms![Form-1].Recordset.Clone
rs.FindFirst "[Class-Name] = '" & Me.Input_Name & "'"
If Not rs.EOF Then Forms![Form-1].Bookmark = rs.Bookmark
Forms![Form-1]![cbx].Value = Me!Input_Name
DoCmd.Close
End Sub
It is failed to display the new record in Form-1 since I cannot find the new record in the RecordsetClone. There is anything wrong?