Record does not show in Combo Box until close/reopen form

S

Song

I have main form with a combo box to search name and add form to add record.
After adding record and close add form, newly added record does not show in
search combo box of main form. I have to close the main form and re-open it
to show the newly added record in the search combo box. How to fix it?
Thanks.
 
D

Dennis

In the Close event of your add form, put this code (substituting your actual
form and combo box name)

[Forms]![MainFormName]![SearchComboBoxName].Requery
 
S

Song

thanks. It shows in comb box. However, I cannot go to newly added record
until after I close and reopen main form. Here is the code:

Private Sub cboFind_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[FullName] = """ & Me![cboFind] & """"
Me.Bookmark = rs.Bookmark
Me.cmdClose.SetFocus
End Sub

Dennis said:
In the Close event of your add form, put this code (substituting your
actual
form and combo box name)

[Forms]![MainFormName]![SearchComboBoxName].Requery



Song said:
I have main form with a combo box to search name and add form to add
record.
After adding record and close add form, newly added record does not show
in
search combo box of main form. I have to close the main form and re-open
it
to show the newly added record in the search combo box. How to fix it?
Thanks.
 
D

Dennis

Instead of the code I provide before
[Forms]![MainFormName]![SearchComboBoxName].Requery

Use this

[Forms]![MainFormName].Requery


Song said:
thanks. It shows in comb box. However, I cannot go to newly added record
until after I close and reopen main form. Here is the code:

Private Sub cboFind_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[FullName] = """ & Me![cboFind] & """"
Me.Bookmark = rs.Bookmark
Me.cmdClose.SetFocus
End Sub

Dennis said:
In the Close event of your add form, put this code (substituting your
actual
form and combo box name)

[Forms]![MainFormName]![SearchComboBoxName].Requery



Song said:
I have main form with a combo box to search name and add form to add
record.
After adding record and close add form, newly added record does not show
in
search combo box of main form. I have to close the main form and re-open
it
to show the newly added record in the search combo box. How to fix it?
Thanks.
 
J

John Spencer

You also need to force the forms recordset to update so that the new
record is available.

Forms!MainFormName.Requery

If you do that you will lose the record that is the current record.

So you may want to do something along the lines of the following when
you close the add form. WARNING: Untested code follows.

Dim strCurrentName as String

With Forms![MainFormName]
strCurrentName = .[FullName]
.Requery
.RecordSetClone.FindFirst "[FullName] = """ & strCurrentName & """"
If RecordsetClone.NoMatch = False then
.Bookmark = RecordsetClone.Bookmark
else
Msgbox "Can't find " & strCurrentName & "!",,"Whoops!"
End IF
End With

Sorry gotta go, grandkids at the door.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

thanks. It shows in comb box. However, I cannot go to newly added record
until after I close and reopen main form. Here is the code:

Private Sub cboFind_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[FullName] = """ & Me![cboFind] & """"
Me.Bookmark = rs.Bookmark
Me.cmdClose.SetFocus
End Sub

Dennis said:
In the Close event of your add form, put this code (substituting your
actual
form and combo box name)

[Forms]![MainFormName]![SearchComboBoxName].Requery



Song said:
I have main form with a combo box to search name and add form to add
record.
After adding record and close add form, newly added record does not
show in
search combo box of main form. I have to close the main form and
re-open it
to show the newly added record in the search combo box. How to fix it?
Thanks.
 
S

Song

I click close button on add form. main form refreshed but add form does NOT
close. Here is my close button code on add from. Both forms use same query
as record source. It that the problem?

Private Sub cmdClose_Click()
[Forms]![frmMaster].Requery

DoCmd.Close , "frmMasterAdd"
End Sub

Dennis said:
Instead of the code I provide before
[Forms]![MainFormName]![SearchComboBoxName].Requery

Use this

[Forms]![MainFormName].Requery


Song said:
thanks. It shows in comb box. However, I cannot go to newly added record
until after I close and reopen main form. Here is the code:

Private Sub cboFind_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[FullName] = """ & Me![cboFind] & """"
Me.Bookmark = rs.Bookmark
Me.cmdClose.SetFocus
End Sub

Dennis said:
In the Close event of your add form, put this code (substituting your
actual
form and combo box name)

[Forms]![MainFormName]![SearchComboBoxName].Requery



:

I have main form with a combo box to search name and add form to add
record.
After adding record and close add form, newly added record does not
show
in
search combo box of main form. I have to close the main form and
re-open
it
to show the newly added record in the search combo box. How to fix it?
Thanks.
 
S

Song

John,

Where to put your lines? Here is my current code but frmMasterAdd does Not
close. See my previouse posting to Dennis

Private Sub cmdClose_Click()
[Forms]![frmMaster].Requery
DoCmd.Close , "frmMasterAdd"
End Sub

John Spencer said:
You also need to force the forms recordset to update so that the new
record is available.

Forms!MainFormName.Requery

If you do that you will lose the record that is the current record.

So you may want to do something along the lines of the following when you
close the add form. WARNING: Untested code follows.

Dim strCurrentName as String

With Forms![MainFormName]
strCurrentName = .[FullName]
.Requery
.RecordSetClone.FindFirst "[FullName] = """ & strCurrentName & """"
If RecordsetClone.NoMatch = False then
.Bookmark = RecordsetClone.Bookmark
else
Msgbox "Can't find " & strCurrentName & "!",,"Whoops!"
End IF
End With

Sorry gotta go, grandkids at the door.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

thanks. It shows in comb box. However, I cannot go to newly added record
until after I close and reopen main form. Here is the code:

Private Sub cboFind_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[FullName] = """ & Me![cboFind] & """"
Me.Bookmark = rs.Bookmark
Me.cmdClose.SetFocus
End Sub

Dennis said:
In the Close event of your add form, put this code (substituting your
actual
form and combo box name)

[Forms]![MainFormName]![SearchComboBoxName].Requery



:

I have main form with a combo box to search name and add form to add
record.
After adding record and close add form, newly added record does not
show in
search combo box of main form. I have to close the main form and
re-open it
to show the newly added record in the search combo box. How to fix it?
Thanks.
 
D

Dennis

I have not tried the way you are closing the form but I always specify the
type, so see if this makes a difference

DoCmd.Close acForm, "frmMasterAdd"

Song said:
I click close button on add form. main form refreshed but add form does NOT
close. Here is my close button code on add from. Both forms use same query
as record source. It that the problem?

Private Sub cmdClose_Click()
[Forms]![frmMaster].Requery

DoCmd.Close , "frmMasterAdd"
End Sub

Dennis said:
Instead of the code I provide before
[Forms]![MainFormName]![SearchComboBoxName].Requery

Use this

[Forms]![MainFormName].Requery


Song said:
thanks. It shows in comb box. However, I cannot go to newly added record
until after I close and reopen main form. Here is the code:

Private Sub cboFind_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[FullName] = """ & Me![cboFind] & """"
Me.Bookmark = rs.Bookmark
Me.cmdClose.SetFocus
End Sub

In the Close event of your add form, put this code (substituting your
actual
form and combo box name)

[Forms]![MainFormName]![SearchComboBoxName].Requery



:

I have main form with a combo box to search name and add form to add
record.
After adding record and close add form, newly added record does not
show
in
search combo box of main form. I have to close the main form and
re-open
it
to show the newly added record in the search combo box. How to fix it?
Thanks.
 
S

Song

Now frmMasterAdd closes. The name does showed on search box BUT I cannot go
to that record until I close frmMaster and reopen it.

Private Sub cmdClose_Click()
[Forms]![frmMaster].Requery
DoCmd.Close acForm, "frmMasterAdd"
End Sub

Dennis said:
I have not tried the way you are closing the form but I always specify the
type, so see if this makes a difference

DoCmd.Close acForm, "frmMasterAdd"

Song said:
I click close button on add form. main form refreshed but add form does
NOT
close. Here is my close button code on add from. Both forms use same
query
as record source. It that the problem?

Private Sub cmdClose_Click()
[Forms]![frmMaster].Requery

DoCmd.Close , "frmMasterAdd"
End Sub

Dennis said:
Instead of the code I provide before
[Forms]![MainFormName]![SearchComboBoxName].Requery

Use this

[Forms]![MainFormName].Requery


:

thanks. It shows in comb box. However, I cannot go to newly added
record
until after I close and reopen main form. Here is the code:

Private Sub cboFind_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[FullName] = """ & Me![cboFind] & """"
Me.Bookmark = rs.Bookmark
Me.cmdClose.SetFocus
End Sub

In the Close event of your add form, put this code (substituting
your
actual
form and combo box name)

[Forms]![MainFormName]![SearchComboBoxName].Requery



:

I have main form with a combo box to search name and add form to
add
record.
After adding record and close add form, newly added record does not
show
in
search combo box of main form. I have to close the main form and
re-open
it
to show the newly added record in the search combo box. How to fix
it?
Thanks.
 
J

John Spencer

Try specifying the object type


Private Sub cmdClose_Click()
[Forms]![frmMaster].Requery
DoCmd.Close acForm, "frmMasterAdd"
End Sub

IF that fails then try the following to make sure you have not
misspelled the form's name.

Private Sub cmdClose_Click()
[Forms]![frmMaster].Requery
DoCmd.Close acForm, Me.Name
End Sub


'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

John,

Where to put your lines? Here is my current code but frmMasterAdd does
Not close. See my previouse posting to Dennis

Private Sub cmdClose_Click()
[Forms]![frmMaster].Requery
DoCmd.Close , "frmMasterAdd"
End Sub

John Spencer said:
You also need to force the forms recordset to update so that the new
record is available.

Forms!MainFormName.Requery

If you do that you will lose the record that is the current record.

So you may want to do something along the lines of the following when
you close the add form. WARNING: Untested code follows.

Dim strCurrentName as String

With Forms![MainFormName]
strCurrentName = .[FullName]
.Requery
.RecordSetClone.FindFirst "[FullName] = """ & strCurrentName & """"
If RecordsetClone.NoMatch = False then
.Bookmark = RecordsetClone.Bookmark
else
Msgbox "Can't find " & strCurrentName & "!",,"Whoops!"
End IF
End With

Sorry gotta go, grandkids at the door.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

thanks. It shows in comb box. However, I cannot go to newly added
record until after I close and reopen main form. Here is the code:

Private Sub cboFind_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[FullName] = """ & Me![cboFind] & """"
Me.Bookmark = rs.Bookmark
Me.cmdClose.SetFocus
End Sub

In the Close event of your add form, put this code (substituting
your actual
form and combo box name)

[Forms]![MainFormName]![SearchComboBoxName].Requery



:

I have main form with a combo box to search name and add form to
add record.
After adding record and close add form, newly added record does not
show in
search combo box of main form. I have to close the main form and
re-open it
to show the newly added record in the search combo box. How to fix it?
Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top