Accessing current record

C

cbnewman

What is the syntax for referring to the underlying record that a form
is currently displaying?

In other words, I would like to make a change to an attribute of a
record that is being displayed when a user clicks a button. I believe
the best way to do this is through modifying the VB code that
underlies the onClick event, but I can't figure out how to reference
the record that is being displayed in the current (or active) record.

In this case, we're dealing with a boolean value (I realize that I
could simply have the checkbox in the form, have the user check or
uncheck the box, then submit the form. In this application, it is more
intuitive to have the user click a button that will simultaneously
commit the transaction and update the attribute). The user uses the
form to search or navigate to a record of interest. When they click
the "Discharge Patient" button, the boolean attribute "is_admitted"
changes to false and the form exits.

How do I reference or modify this data? Seems like I could generate a
SQL statement and submit it (in this case, I would still have to know
how to reference the current record within the SQL statement, I'm also
not sure how to submit a SQL statement within VBA). But it also seems
logical that there might be a way to modify the record within the form
itself (i.e. set currentRecord.is_admitted to FALSE) using just VBA.

Thanks,
--b
 
S

SusanV

Add a checkbox for the Boolean field to the form, but set it's Visible
property to No. Then in the onclick event, use the line Me.MyCheckbox =
false
 
L

Larry Linson

Assuming the Field is in the Form's RecordSet... for example, for a Field
named Boo, the click event would be

Me.Boo = True 'Set the Yes/No Field
Me.Dirty = False 'Cause Record to be Saved

Larry Linson
Microsoft Access MVP
 
A

Albert D. Kallal

If the form is bound, then you can go:


me.NameOfBoField = true

However, if the form is bound at a runtime (ie: you change the reocrd source
via code), then you find that the above will not work, and you have to use:


me!NameOfBolField = true


So, the code behind a buttion to change the field value, and then force a
disk write of the current form would be:

me!NameOfBolField = true
me.dirty = False
 
J

John W. Vinson

How do I reference or modify this data? Seems like I could generate a
SQL statement and submit it

You're making it a LOT harder than it needs to be. Just include the field in
the Form's Recordsource query; you do not need to put a control on the form
for it. In your event simply put

Me!yesnofield = True

or whatever value you want to assign it.

John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top