Howto lock a record?

  • Thread starter Thread starter Bob M.
  • Start date Start date
B

Bob M.

Hello,
How do I lock/unlock a recordID so that it can be carried over onto a new
form or a report?
I cannot seem to open the forms or reports with the displayed main form
information.
TIA
Bob
 
How do I lock/unlock a recordID so that it can be carried over onto a new
form or a report?
I cannot seem to open the forms or reports with the displayed main form
information.

I'm not sure what you mean by "lock/unlock a recordID", but if you are trying to
open FormB from FormA to display a record sharing the same key value, then the
following approach using the "OpenForm" method and its "WhereCondition" argument
should work

'If the key value is an autonumber or other number
DoCmd.OpenForm "FormB", , , "recordID=" & Me!recordID

'If the key value is text
DoCmd.OpenForm "FormB", , , "recordID=""" & Me!recordID & """"

Just make sure that the record is saved (especially if it's a "new" record -
just check the "Dirty" property of the form and, if True, set that property to
"False" before issuing the "OpenForm") and note that if FormB is to contain data
from a table other than that in FormA, that table must contain data with a
matching key or FormB will open with an empty recordset.

If you are trying to generate a new child record to be related to the "main
form" record, this takes a slightly different approach. Let us know if this is
what you are trying to do.
 
Thank you Bruce.
FormA pulls recorded data from a table then by pressing a button FormB is
triggered. The latter has additional records from the same table.
Then FormB triggers via a button the view and/o the printing of a Report.
RecordID should be pulled from FormA and maintained for FormB and its
Reports.
I have some like shown below but it's not working.

Sub BookNo_AfterUpdate()
' Find the record that matches the control.
Me.RecordsetClone.FindFirst "[BookNo] = " & Me![BookNo]
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub
 
Thank you Bruce.
FormA pulls recorded data from a table then by pressing a button FormB is
triggered. The latter has additional records from the same table.
Then FormB triggers via a button the view and/o the printing of a Report.
RecordID should be pulled from FormA and maintained for FormB and its
Reports.

So, what is the connection between the record displayed in FormA and the
"additional records" displayed in FormB and that displayed in the report? Do you
mean that FormB displays additional *fields* in the same record as that
displayed in FormA?
 
Yes.
FormA contains most fields of a record set. FormB contains additional fields
and a *Notes* field from the same record set.
FormB is used to update the notes of a given record set and then once saved,
the information is sent to a Report to be printed. The Report uses a
qryTable to pull the information.
RecordID is the same for FormA, FormB and for the Report.
 
Yes.
FormA contains most fields of a record set. FormB contains additional fields
and a *Notes* field from the same record set.
FormB is used to update the notes of a given record set and then once saved,
the information is sent to a Report to be printed. The Report uses a
qryTable to pull the information.
RecordID is the same for FormA, FormB and for the Report.

So, are you saying that the example I provided earlier wasn't working? The code
you provided does not do anything, unfortunately and is below:
Sub BookNo_AfterUpdate()
' Find the record that matches the control.
Me.RecordsetClone.FindFirst "[BookNo] = " & Me![BookNo]
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub

What the above code does is to "find" the current record, so nothing happens
(you're already on the current record). My examples demonstrate how to open a
form to the same record currently displayed on the "calling" form. The same
technique works with the "OpenReport" method (both the "OpenForm" and
"OpenReport" methods are explained in Access Help). When either method is
invoked, you should precede the lines containing the code opening the form or
report with the following to ensure that the most recent changes, if any, have
been saved to the table:

'Save any data changes or additions
If Me.Dirty Then
Me.Dirty = False
End If

I suggest you take another look at the examples I gave you - this is the
technique I normally use in my applications unless there are unusual
requirements that dictate otherwise. If you are still having difficulties, post
a response to this message with specific questions and provide as much detail
about your problem and any related error messages as you can.
 
Back
Top