Programming novice here...but I'm slowly gaining steam. I have a form with two controls on it for the user to enter the geographic coordinates of the location they are at when collecting information in the field. The controls are named "intXCoordinate" and "intYCoordinate". I've tried to get versions of the code below to work on a couple different events, and came across a forum discussion that advocated the On Exit event. So that is where I'm at now. Basically, I want the user to get a message box if they have entered a value that is outside the geographic range for the state. FYI - There is an input mask on the source field to ensure format consistency. If the user enters a value outside the range, then the message box will pop up and the value that was entered into the control will be cleared. This appears to work with the following code. However, if I open the form and try to go to Design View, I get the Runtime Error ‘94’ saying Invalid Use of Null. I’ve tried using some Error Handling but am fumbling in the dark. How do I achieve my message box objectives programmatically without getting an error every time I want to switch to Design View? Should this (or similar) code be on a different event? What am I missing?
Thanks,
David
Thanks,
David
Code:
Private Sub intXCoordinate_Exit(Cancel As Integer)
'Declare variables
Dim intXCoordinateValue As Integer
'Define values for variables
intXCoordinateValue = intXCoordinate
'If statement to ensure X Coordinate is within range for the state
If intXCoordinateValue = Null Then
MsgBox "You have not entered an X Coordinate."
ElseIf intXCoordinateValue < -84.321824 Then
MsgBox "The value entered is outside the parameters for the state." & vbNewLine & vbNewLine & "X Coordinate must be between -84.321824 and -75.459656."
intXCoordinate.Value = Null
Cancel = True
ElseIf intXCoordianteValue > -75.459656 Then
MsgBox "The value entered is outside the parameters for the state." & vbNewLine & vbNewLine & "X Coordinate must be between -84.321824 and -75.459656."
intXCoordinate.Value = Null
Cancel = True
Else: DoCmd.GoToControl "intYCoordinate"
End If
End Sub