Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

requery command in Access form

Status
Not open for further replies.

mvital

Technical User
Jul 2, 2003
128
US
I have a main form with a command button. This button opens a small pop-up form where I can add building information for a new building.
I enter info on the pop-up form and then close it to return to the main form. I want the newly added building information to be available so that I can capture the rest of the information for that building on the main form.

This is the code I have (on the save command button on the pop up form), do not get an error, but it still does not work. The only way it works is if I close the main form and open it again; don't want to do this. What am I doing wrong? I am new to VBA.

Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click

Dim BUILDING_NAME As String

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

DoCmd.Requery
DoCmd.OpenForm ("frm_main_data_entry"), acNormal, , , acFormEdit, acWindowNormal, "edit"
DoCmd.Close acForm, "frm_project_building_information"

Exit_cmdSave_Click:
Exit Sub

Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click

End Sub

thanks in advance!
 
A few notes.

Code:
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click

Dim BUILDING_NAME As String

'This wizard code is a little out of date
'DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.RunCommand accmdSaveRecord

'You need to requery the main form, so if the main form
is called frm_main_data_entry and it is open, you can say:
Forms!frm_main_data_entry.Requery
'DoCmd.Requery

'Not sure what this is for, I think you said the main form
'is already open
'DoCmd.OpenForm ("frm_main_data_entry"), acNormal, , , acFormEdit, acWindowNormal, "edit"
DoCmd.Close acForm, "frm_project_building_information"

Exit_cmdSave_Click:
    Exit Sub

Err_cmdSave_Click:
    MsgBox Err.Description
    Resume Exit_cmdSave_Click
    
End Sub
 
THANK YOU REMOU!! You always help me out. :) I've been troubleshooting this a while could not see what I was doing wrong!

Have a great day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top