I have a database that saves customer price lists. On the main form (ListMaintenance), i have a button to add a new item to the list. A blank bound (to pricelist_detail) form (AddNewItem) pops up that contains all the fields associated with an item and the user fills in the appropriate information. Once they're done, there is a save button (see below code) that saves the info and should close the pop-up form, but the form seems to close and reopen, becausese I see a quick flash of the main form and then I get the add new item form open and ready to recieve info.
there must be something else that is keeping the form from closing or is causing it to reopen - is there some sort of form property that can cause this?
This is what happens when the AddItem button is clicked on the main form:
This is the code behind the Save button in the AddNewItem pop up form:
I must say that I don't mind it reopening (and neither do the users), since it allows the them to keep on adding new items without having to keep on clicking on add new item button. The reason it's a problem now is because after they click on save and they get a blank form again, the focus is set on a field in the middle of the form instead of up at the top where it should be. i thought it was going to be a simple SetFocus issue, but when I realized that the form would automatically reopen, I tried setting the focus to the first field on form load but that didn't make a difference. Does this mean that form never actually closes? if not, why not if I tell it to close in my code?
This was a little difficult for me to explain, if I need be a little more clear, please let me know.
Sandy
there must be something else that is keeping the form from closing or is causing it to reopen - is there some sort of form property that can cause this?
This is what happens when the AddItem button is clicked on the main form:
Code:
Private Sub cmdAddItem_Click()
DoCmd.Save
DoCmd.OpenForm "PriceList_AddNewItem"
Forms!PriceList_AddNewItem!PriceListID = Forms!PriceList_Maintenance!PriceListID
End Sub
This is the code behind the Save button in the AddNewItem pop up form:
Code:
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
CheckBreaks 'blank out the breaks with "[Break]" as heading
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.OpenQuery "3_1_CreateRecordInTable3"
DoCmd.OpenQuery "3_2_UpdateBreakNamesInBreakTable"
Forms!PriceList_Maintenance.Refresh
DoCmd.Close acForm, "PriceList_AddNewItem"
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
End Sub
I must say that I don't mind it reopening (and neither do the users), since it allows the them to keep on adding new items without having to keep on clicking on add new item button. The reason it's a problem now is because after they click on save and they get a blank form again, the focus is set on a field in the middle of the form instead of up at the top where it should be. i thought it was going to be a simple SetFocus issue, but when I realized that the form would automatically reopen, I tried setting the focus to the first field on form load but that didn't make a difference. Does this mean that form never actually closes? if not, why not if I tell it to close in my code?
This was a little difficult for me to explain, if I need be a little more clear, please let me know.
Sandy