Further to a previous thread... and valuble advice from Minty about being able to have a subform of a continuous form (in the footer)...
I have a continuous form (fLocation) based off a query (Record Source: SELECT * FROM qLocation) which in turn is based off a table (tLocation, which has autonumber PK called IDLocation, txt field called Room, then a bunch of FIDs that link to other tables, and some number fields). The FIDs are the reason for the use of qLocation to make the continuous form has meaningful data displayed.
I then have, in the header, a filter, so I can filter what the continuous form displays.
In the footer I have:
1) Sum text fields that sum up some number fields in the continuous form based on the current filter.
2) a single record view sub form which displays whichever record is selected at the time in the continuous form.
This is called fLocationSubform and it's Record Source is tLocation to enable editing and the FIDs are bound to cboboxes to show meaningful data.
When this subform is in place, the SourceObject is: fLocationSubform, and the Link Master Fields and Link Child Fields are both set to IDLocation.
I can edit a record and have it update the continuous form without issue.
This issue I'm having is with the new record not automatically assigning and unique UNUSED ID.
When I click my cmdNew button which is on the tLocationSubform (and created via the button wizard: Record operations > add new record) it gives me a blank record on the fLocationSubform as you'd expect prior to data entry, with (new) in the IDLocation field. Directly I start to enter data (when the ID gets assigned) it gives me the ID of the currently selected record in the continuous form rather than a new one (yes IDLocation is AutoNumber).
I then obviously get the "The changes you requested to the table were not successful because they would create duplicate values..." message.
Why is it doing this? Why is it not picking up a new, unused ID? And what can I do about it?
I changed the embedded macro that the button wizard creates to this but no joy to preventing the used ID issue:
I have a continuous form (fLocation) based off a query (Record Source: SELECT * FROM qLocation) which in turn is based off a table (tLocation, which has autonumber PK called IDLocation, txt field called Room, then a bunch of FIDs that link to other tables, and some number fields). The FIDs are the reason for the use of qLocation to make the continuous form has meaningful data displayed.
I then have, in the header, a filter, so I can filter what the continuous form displays.
In the footer I have:
1) Sum text fields that sum up some number fields in the continuous form based on the current filter.
2) a single record view sub form which displays whichever record is selected at the time in the continuous form.
This is called fLocationSubform and it's Record Source is tLocation to enable editing and the FIDs are bound to cboboxes to show meaningful data.
When this subform is in place, the SourceObject is: fLocationSubform, and the Link Master Fields and Link Child Fields are both set to IDLocation.
I can edit a record and have it update the continuous form without issue.
This issue I'm having is with the new record not automatically assigning and unique UNUSED ID.
When I click my cmdNew button which is on the tLocationSubform (and created via the button wizard: Record operations > add new record) it gives me a blank record on the fLocationSubform as you'd expect prior to data entry, with (new) in the IDLocation field. Directly I start to enter data (when the ID gets assigned) it gives me the ID of the currently selected record in the continuous form rather than a new one (yes IDLocation is AutoNumber).
I then obviously get the "The changes you requested to the table were not successful because they would create duplicate values..." message.
Why is it doing this? Why is it not picking up a new, unused ID? And what can I do about it?
I changed the embedded macro that the button wizard creates to this but no joy to preventing the used ID issue:
Code:
Private Sub cmdNewRecordV2_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tLocation", dbOpenDynaset)
With rs
.AddNew
!FIDBuilding = cboFIDBuilding
!Room = txtRoom
!FIDUsage = cboFIDUsage
[COLOR=Green] 'etc[/COLOR]
.Update
End With
Me.AllowAdditions = False
rs.Close
Set rs = Nothing
End Sub