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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem in Null value!

Status
Not open for further replies.

NekiQ

Programmer
Feb 24, 2003
6
0
0
BG
I had inserted a textbox called Year and a command button called Open. Upon clicking on the 'Open' button, it will link me to another page. But the problem is, if the textbox 'Year' is not filled, I wanted it to show a msgbox asking the user to type in the Year. But the code can't work. Can anyone help me with this? Thank You!

Private Sub Open_Click()

If Year = Null Then
MsgBox "Please enter the year"
Else
On Error GoTo Err_Open_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "123"

stLinkCriteria = "[Year]=" & "'" & Me![Year] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

End If

Exit_Open_Click:
Exit Sub

Err_Open_Click:
MsgBox Err.Description
Resume Exit_Open_Click

End Sub
 
Private Sub Open_Click()

TRY

If isnull(year)Then
MsgBox "Please enter the year"
Else
On Error GoTo Err_Open_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "123"

stLinkCriteria = "[Year]=" & "'" & Me![Year] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

End If

Exit_Open_Click:
Exit Sub

Err_Open_Click:
MsgBox Err.Description
Resume Exit_Open_Click

End Sub

hope this helps
 
From Microsoft Access Help file:

IsNull Function Example

The following example uses the IsNull function to determine whether the value of a control is Null. If it is, a message prompts the user to enter data. If the value is not Null, a message displays the value of the control.

Sub ControlValue(ctlText As Control)
Dim strMsg As String

' Check that control is text box.
If ctlText.ControlType = acTextBox Then
' If value of control is Null, prompt for data.
If IsNull(ctlText.Value) Then
strMsg = "No data in the field '" & ctlText.Name _
& "'." & vbCrLf & "Please enter data for " _
& "this field now."
If MsgBox(strMsg, vbQuestion) = vbOK Then
Exit Sub
End If
' If value is not Null, display value.
Else
MsgBox (ctlText.Value)
End If
End If
End Sub
 
Thank You for your help! it works...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top