Hi MVP (including previous posts)
Some assistance please on our situation - post migration,
I have read this in brief detail, but certainly a lot of issues post migration
https://www.codeproject.com/Tips/646080/Migrating-Access-Jet-Data-to-SQL-Server
and
ttps://regina-whipp.com/blog/?p=371
We currently have crosstab query, to which we double click on a particular matrix area.
This launches a form via vba code that is triggered on the doubl click event
DoCmd.OpenForm frmName, WhereCondition:="ID=" & 0
The form that is launched has ID (autonumber).
The field is blank, which used to get auto populated with the next id.
At this point I wish to just populate the autonumber field (without saving the form), as there are other fields that need to be filled in, or the user may simply cancel the form entries, and just click a cancel/close button on the form. It does not matter
if the autonumber field increments through this entry/'cancel,
because there is further VBA code that populates the next field.
Forms(frmName).Controls.Item("Job Number").Value = IIf(IsNull([Forms]![Dashboard Details]![Job Number]), "A" & 100000 + [Forms]![Dashboard Details]![ID], "")
Is it such that we put the following code (not quite sure the entire structured syntax)... if there is a little example i can follow please
rs. AddNew
rs. Update
rs.Move 0, rs.LastModified
lngNewID = rs!ID
Thank you kindly.
References:
In that article above:
- that autonumber/GUID fields in SQL Server only update on COMMIT, rather than when first created as in
Access. That has made using a bound form to add new records very tricky indeed! (Not sure this is entirely true, but difficult
to test.) In the end, I used a Stored Procedure and an associated Access pass-through query to add records and return the
allocated GUID to the application (as a Recordset).
14.
A variation on the problems related to items 7 and 9 (in the article): If you have a bound sub-form (even just to a table) and want to
prevent the user simply typing in the offered blank new record, you can turn off the "Allow Additions" property. However,
this also means that you cannot - directly - add a record using VBA by manipulating the recordset associated with the form.
Instead you must use a separate recordset, Stored Procedure, etc. to add a suitable blank/prefilled new record and then
refresh the sub-form.
If you use VBA to add a record to a linked table with an IDENTITY field or GUID, then to make the new record current in
the recordset ("rs" in this example) used you need to add the following commands after using .AddNew and amending
any fields:
rs.Update
rs.Move 0,rs.lastModified
If the table or a query built with it is bound to a form and you are attempting to add a new record whilst viewing the form,
then...
Me.Requery
...is also required to force the form to update.