C
chopper57 via AccessMonster.com
Popup used to add new data such as a Job Site Number doesn't synchronize
When Database is open the Site numbers in the combo box are in ascending
order, and the SubForm goes to the last record. (this is what I want)
MainForm (frm_MainForm) with only one Combo Box to choose a Site Number
SubForm (sfrm_DailyReport) with fields for data.
PopupForm (pfrm_Site) to add new Site Number
(Popup is a second level popup: I have a MainPopup (pfrm_UpdateData) with
cmdbuttons for other Popups to enter data, and it’s the same scenario for
them all)
Popup form works fine when you open the database and you don’t navigate from
the first record shown.
I open the PopupForm enter the new Site number, close PopupForm, choose new
site number from combo on MainForm and the SubForm shows a new record for the
new site.
If I open the database and navigate from the fist Site number to input data
and then decide to add a new Site number this is what happens:
Open PopupForm, add new Site number, close PopupForm, choose newly added Site
number from combo on MainForm and the Subform reverts back to the records of
the fisrt Site number shown when the database is open.
This is the code that I have on the forms:
1. MainForm (frm_MainForm) Code:
Private Sub Combo1_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Site] = '" & Me![Combo1] & "'"
Me.Bookmark = rs.Bookmark
End Sub
Private Sub Form_Current()
DoCmd.GoToControl "sfrm_DailyReport"
DoCmd.GoToRecord , , acLast
End Sub
Private Sub Form_Load()
Me.Combo1 = Me.Combo1.Column(0, 0)
End Sub
2. PopupForm (pfrm_Site) Code:
Private Sub Form_Close()
Forms!frm_MainForm!Combo1.Requery
DoCmd.Close acForm, "pfrm_UpdateData"
‘Closes the main popup when you close the Site popup
End Sub
3. SubForm (sfrm_DailyReport) Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
'Auto increments a sequential number for ReportNo
If Me.NewRecord Then
Me.ReportNo = Format(Nz(DMax("[ReportNo]", "qry12_DailyReport", _
"[Site]=" & "Forms![frm_MainForm]![Combo1]"), 0) + 1, "0000")
End If
End Sub
Private Sub Form_Current()
lblNew.Visible = Me.NewRecord
cboDate = AutoNo
cboReportNo = AutoNo
Date.SetFocus
End Sub
Private Sub Form_Load()
DoCmd.GoToRecord , , acLast
End Sub
Private Sub cmdUpDateData_Click()
'Open main Popup Form
On Error GoTo Err_cmdUpDateData_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "pfrm_UpdateData"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_cmdUpDateData_Click:
Exit Sub
Err_cmdUpDateData_Click:
MsgBox Err.Description
Resume Exit_cmdUpDateData_Click
End Sub
Private Sub Form_Open(Cancel As Integer)
DoCmd.Maximize
End Sub
When Database is open the Site numbers in the combo box are in ascending
order, and the SubForm goes to the last record. (this is what I want)
MainForm (frm_MainForm) with only one Combo Box to choose a Site Number
SubForm (sfrm_DailyReport) with fields for data.
PopupForm (pfrm_Site) to add new Site Number
(Popup is a second level popup: I have a MainPopup (pfrm_UpdateData) with
cmdbuttons for other Popups to enter data, and it’s the same scenario for
them all)
Popup form works fine when you open the database and you don’t navigate from
the first record shown.
I open the PopupForm enter the new Site number, close PopupForm, choose new
site number from combo on MainForm and the SubForm shows a new record for the
new site.
If I open the database and navigate from the fist Site number to input data
and then decide to add a new Site number this is what happens:
Open PopupForm, add new Site number, close PopupForm, choose newly added Site
number from combo on MainForm and the Subform reverts back to the records of
the fisrt Site number shown when the database is open.
This is the code that I have on the forms:
1. MainForm (frm_MainForm) Code:
Private Sub Combo1_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Site] = '" & Me![Combo1] & "'"
Me.Bookmark = rs.Bookmark
End Sub
Private Sub Form_Current()
DoCmd.GoToControl "sfrm_DailyReport"
DoCmd.GoToRecord , , acLast
End Sub
Private Sub Form_Load()
Me.Combo1 = Me.Combo1.Column(0, 0)
End Sub
2. PopupForm (pfrm_Site) Code:
Private Sub Form_Close()
Forms!frm_MainForm!Combo1.Requery
DoCmd.Close acForm, "pfrm_UpdateData"
‘Closes the main popup when you close the Site popup
End Sub
3. SubForm (sfrm_DailyReport) Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
'Auto increments a sequential number for ReportNo
If Me.NewRecord Then
Me.ReportNo = Format(Nz(DMax("[ReportNo]", "qry12_DailyReport", _
"[Site]=" & "Forms![frm_MainForm]![Combo1]"), 0) + 1, "0000")
End If
End Sub
Private Sub Form_Current()
lblNew.Visible = Me.NewRecord
cboDate = AutoNo
cboReportNo = AutoNo
Date.SetFocus
End Sub
Private Sub Form_Load()
DoCmd.GoToRecord , , acLast
End Sub
Private Sub cmdUpDateData_Click()
'Open main Popup Form
On Error GoTo Err_cmdUpDateData_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "pfrm_UpdateData"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_cmdUpDateData_Click:
Exit Sub
Err_cmdUpDateData_Click:
MsgBox Err.Description
Resume Exit_cmdUpDateData_Click
End Sub
Private Sub Form_Open(Cancel As Integer)
DoCmd.Maximize
End Sub