Michael,
Here's what I did to get it working. Assume Form1 is attached to a table
with an autonumber ID and X and Y fields that are numbers.
I made a form and placed an image control on it (Image1). I also created two
non visible fields (Visible property set to false) called YCoord and XCoord
to hold the X and Y coordinates of the click. These fields are bound to the
X and Y fields in the table. Lastly, I created a Box object on the form and
made it quite small. I called this "box".
Try out the following code and adapt to your needs. Any questions, feel free
to post back and ask:
' form has had record change, adjust the marker for the new record's data
Private Sub Form_Current()
Call UpdateMarker
End Sub
' form first loaded, place the marker according to the current record data
Private Sub Form_Load()
Call UpdateMarker
End Sub
' Image 1 was clicked and the mouse button released.
' Calculate the new position of the click and store in the
' proper controls
Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single,
Y As Single)
XCoord.Value = X
YCoord.Value = Y
' update the position and color of the box indicating the click location
Call UpdateMarker
End Sub
Private Sub UpdateMarker()
Dim X, Y As Single
' get the coordinates of the click for this record
If Not IsNull(XCoord.Value) And XCoord.Value <> "" Then
X = CSng(XCoord.Value)
Else
X = 0
End If
If Not IsNull(YCoord.Value) And YCoord.Value <> "" Then
Y = CSng(YCoord.Value)
Else
Y = 0
End If
' place the marker
box.Left = Image1.Left + X
box.Top = Image1.Top + Y
' depending on which quadrant the marker is in, set the color
accordingly
If X < 1000 And Y < 1000 Then
box.BorderColor = RGB(240, 0, 0)
ElseIf X >= 1000 And Y < 1000 Then
box.BorderColor = RGB(0, 240, 0)
ElseIf X < 1000 And Y >= 1000 Then
box.BorderColor = RGB(0, 0, 240)
Else
box.BorderColor = RGB(240, 240, 240)
End If
End Sub
' may be redundant. Experiment regarding whether these are needed or not.
Private Sub XCoord_AfterUpdate()
Call UpdateMarker
End Sub
Private Sub YCoord_AfterUpdate()
Call UpdateMarker
End Sub