Use Re-query and RepaintObject Action

I

iholder

Am I using these actions correctly. I am not achieving the correct results.

The main form is "frmEmployeeLabels" . On this form is a command add button
to add a new employee. add button code:
Private Sub cmdAdd_Click()
On Error GoTo Err_cmdAdd_Click
Dim stDocName As String
stDocName = "frmAddEmployees"
DoCmd.OpenForm stDocName, , , , acFormAdd

Exit_cmdAdd_Click:
Exit Sub

Err_cmdAdd_Click:
MsgBox Err.Description
Resume Exit_cmdAdd_Click

End Sub

On this form the "close form button" code is:

Private Sub cmdCloseForm_Click()
On Error GoTo Err_cmdCloseForm_Click

Dim ctlFullName As Control
' Return Control object pointing to a text box.
Set ctlFullName = Forms!frmEmployeelabels!FullName

' Requery source of data for list box.
ctlFullName.Requery

DoCmd.RepaintObject acForm, "frmEmployeelabels"
DoCmd.Close

Exit_cmdCloseForm_Click:
Exit Sub

Err_cmdCloseForm_Click:
MsgBox Err.Description
Resume Exit_cmdCloseForm_Click

End Sub

I am trying to update query list on main "frmEmployeeLabels" after an
employee is add from the add employee form.

New employee added does not appear only after closing and opening the main
form.

Help needed with correct coding.

Thank you.
 
D

Dirk Goldgar

iholder said:
Am I using these actions correctly. I am not achieving the correct
results.

The main form is "frmEmployeeLabels" . On this form is a command add
button to add a new employee. add button code:
Private Sub cmdAdd_Click()
On Error GoTo Err_cmdAdd_Click
Dim stDocName As String
stDocName = "frmAddEmployees"
DoCmd.OpenForm stDocName, , , , acFormAdd

Exit_cmdAdd_Click:
Exit Sub

Err_cmdAdd_Click:
MsgBox Err.Description
Resume Exit_cmdAdd_Click

End Sub

On this form the "close form button" code is:

Private Sub cmdCloseForm_Click()
On Error GoTo Err_cmdCloseForm_Click

Dim ctlFullName As Control
' Return Control object pointing to a text box.
Set ctlFullName = Forms!frmEmployeelabels!FullName

' Requery source of data for list box.
ctlFullName.Requery

DoCmd.RepaintObject acForm, "frmEmployeelabels"
DoCmd.Close

Exit_cmdCloseForm_Click:
Exit Sub

Err_cmdCloseForm_Click:
MsgBox Err.Description
Resume Exit_cmdCloseForm_Click

End Sub

I am trying to update query list on main "frmEmployeeLabels" after an
employee is add from the add employee form.

New employee added does not appear only after closing and opening the
main form.

Help needed with correct coding.

Thank you.

I think what you want to do is just requery frmEmployeeLabels in the
Close event of frmAddEmployees:

'----- start of suggested code -----
Private Sub cmdCloseForm_Click()

On Error GoTo Err_cmdCloseForm_Click

If CurrentProject.AllForms("frmEmployeeLabels").IsLoaded Then
Forms!frmEmployeeLabels.Requery
End If

Exit_cmdCloseForm_Click:
Exit Sub

Err_cmdCloseForm_Click:
MsgBox Err.Description
Resume Exit_cmdCloseForm_Click

End Sub

'----- end of suggested code -----
 
I

iholder

Thank you
Dirk,

I add one more line to your code before the re-query.
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
It works just fine.
 

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