I
Irene_58
I have a table (tPNos) containing Project info. The ProjectNo is a text
field because we have sub-projects with descriptive suffixes (e.g. 1400,
1400-01, 1400os). The first 4 digits are always numeric and equate to a
BasePno. I also have an auto-number PNumId field, that I use to link to
other tables.
I have a form based on tPNos, with a sub form on the left that has a list of
all the ProjectNos & descriptions. As the user moves up & down the list, I
use the OnCurrent event to filter to the appropriate record in the main form
– so the form fields fill in correctly.
I originally had the sub-form with AllowAdditions enabled, but the users
aren’t very used to Access and asked for buttons to add new records. 2
flavours - cmdNewPno to create a new record with the Pno based on the next
free BaseNo and cmdAddStroke to create a new record based on the selected PNo.
I disabled AllowAdditions on the sub-form and created buttons on the main
form as requested. The OnClick event of the buttons simply did a
Me.Recordset.AddNew and set the text boxes on the main form to the
appropriate values. The Save button did a DoCmd.DoMenuItem acFormBar,
acRecordsMenu, acSaveRecord, , acMenuVer70.
This seemed to work ok, and has been running like this for some months.
However, I recently tried to modify this form so that under certain
circumstances of adding a new Project it also creates a record in a separate
(quote) table and pre-fills a field in that with the new PNumId. Which is
when I realised that my approach isn’t working properly. My auto-id is going
up in steps of 2. The PNumId I have when moving through the form fields and
creating the quote record is one greater than the last auto-num as I expect,
but when the save is complete there is no record with this number, but a
properly completed record but with an auto-num of plus 2.
I did try changing the save to Me.Recordset.Update – but this only made it
clearer that I’m dealing with 2 different records, as the update doesn’t have
the data on my form.
Any help greatfully appreciated.
Code Extracts:
Private Sub cmdNewPno_Click()
On Error GoTo ErrHandler
Me.Recordset.AddNew
txtProjectNo = GetLastPno() + 1
Exit Sub
ErrHandler:
MsgBox Err.Description
End Sub
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me.sfPnos.SetFocus
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
End Sub
field because we have sub-projects with descriptive suffixes (e.g. 1400,
1400-01, 1400os). The first 4 digits are always numeric and equate to a
BasePno. I also have an auto-number PNumId field, that I use to link to
other tables.
I have a form based on tPNos, with a sub form on the left that has a list of
all the ProjectNos & descriptions. As the user moves up & down the list, I
use the OnCurrent event to filter to the appropriate record in the main form
– so the form fields fill in correctly.
I originally had the sub-form with AllowAdditions enabled, but the users
aren’t very used to Access and asked for buttons to add new records. 2
flavours - cmdNewPno to create a new record with the Pno based on the next
free BaseNo and cmdAddStroke to create a new record based on the selected PNo.
I disabled AllowAdditions on the sub-form and created buttons on the main
form as requested. The OnClick event of the buttons simply did a
Me.Recordset.AddNew and set the text boxes on the main form to the
appropriate values. The Save button did a DoCmd.DoMenuItem acFormBar,
acRecordsMenu, acSaveRecord, , acMenuVer70.
This seemed to work ok, and has been running like this for some months.
However, I recently tried to modify this form so that under certain
circumstances of adding a new Project it also creates a record in a separate
(quote) table and pre-fills a field in that with the new PNumId. Which is
when I realised that my approach isn’t working properly. My auto-id is going
up in steps of 2. The PNumId I have when moving through the form fields and
creating the quote record is one greater than the last auto-num as I expect,
but when the save is complete there is no record with this number, but a
properly completed record but with an auto-num of plus 2.
I did try changing the save to Me.Recordset.Update – but this only made it
clearer that I’m dealing with 2 different records, as the update doesn’t have
the data on my form.
Any help greatfully appreciated.
Code Extracts:
Private Sub cmdNewPno_Click()
On Error GoTo ErrHandler
Me.Recordset.AddNew
txtProjectNo = GetLastPno() + 1
Exit Sub
ErrHandler:
MsgBox Err.Description
End Sub
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me.sfPnos.SetFocus
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
End Sub