Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Form Records via a module

Status
Not open for further replies.

ColdUpNorth

Technical User
Oct 14, 2002
6
GB
I'm sure this is easy but I'm new to VBA/Access.
When a form is open with a record visable, at a number of places I need to carry out some logical tests between fields in the record. The answer is to have a single block of code that carries out a check on all data and changes some records as it executes. If the form had an "Event", "On Change". For any filed change then this would be ideal. Since, this isn't the case I want a module code to perfrom the operation. A simple call is fine at the places in the form that need the check. But the problem I have is how to access the fields (read and write) from the VBA msodule.
 
Hi

Assuming you form is a bound form, then you can address the fields using by simply refering to the name of the control and since it is bound, you will be presented with the value from the table, for the current record.

If you have the code within the form, you can use Me!ControlName syntax, if you have a public function od sub, say in a code module, you can pass the Me keyword to it via a form variable eg

Dim frm as Form

DoMyCode Me

...

Public DoMyCode(frm As Form)
If frm!MyControlName = ..etc

I do not quite follow you assertion that there is no event to accomodate this, Without knowing exactly what you are trying to accomplish, I would have thought taht the oncurrent, or beforeupdate events of the form where good possibilities.
Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
I might also add that the 'afterupdate' or 'lostfocus' events for particular controls may come in handy.
 
Ken,

As I suspected that was easy, in fact once I read your thread I was a annoyed that I hadn’t remembered to do it via the ‘Me’ keyword.

Many thanks for the help

Ian.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top