Navigation buttons

  • Thread starter Thread starter Sam Y.
  • Start date Start date
S

Sam Y.

I was wondering if there was a way to trigger an event when navigating
between records? I could not find it in the form properties. For example, if
I wanted to run a SQL query in the event of moving from one record to another
to populate a textbox with a piece of information associated with the record
from a different table. I don't know if that makes much sense...
 
Sam,
you can use the On Current event. This event fires every time the form goes
to another record.

Jeanette Cunningham
 
To do something EVERYTIME you move from record to record:

Private Sub Form_Current()
'Place your code here
End Sub

To do something ONLY when the record moved to is AN EXISTING RECORD, which is
what it sounds like you're wanting to do (you can't look up associated info
on a record that doesn't exist yet, after all)

Private Sub Form_Current()
If Not Me.NewRecord Then
'Place your code here
End If
End Sub

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
This worked just fine. Thanks for the help. Another tip for anyone else who
tries to do this. I was trying to do a SQL query to get a distinct value that
is linked with the current tables primary key. I tried the DoCmd.RunSQL, but
that doesn't return a value (I don't think a SELECT query works, only
update/delete/etc). So I used DLookup.

There are three tables I am requiring information from: Softwares,
software_maintenance, and maintenance agreement.
software_maintenance is the bridge (it only has SoftwareID and MaintenanceID).

Dim SID As Variant
SID = DLookup("softwareID", "software_maintenance",
"[software_maintenance.maintenanceid] = " & Forms![maintenance
agreement]!MaintenanceID)
If IsNull(SID) Then
Me!title = ""
Else
Me!title = DLookup("title", "softwares", "[softwareid] = " & SID)
End If
Else
Me!title = ""

It all looks more complicated than it really is... and I'm sure no one is
really going to be using the same database structure as I am. Oh well...
 
Back
Top