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

Object Required Error When Referencing A Text Box On A Form 2

Status
Not open for further replies.
Feb 6, 2003
48
US
Hi-

I have a basic Access form where a user enters a from and thru date. When they click the button those dates are then converted and used as selection criteria in a query. This was working just fine until I added code trap for blank text boxes.

Option Explicit
Public Sub Command6_Click()

Dim From As String
Dim Thru As String
Dim Temp1 As String
Dim Temp2 As String
Dim Yr1 As String
Dim Yr2 As String
Dim Mo1 As String
Dim Mo2 As String
Dim Dy1 As String
Dim Dy2 As String

If Form_frmMainForm.Text2.Value Is Null Or Form_frmMainForm.Text4.Value Is Null Then
If MsgBox("From and Thru Dates Cannot Be Blank", vbOKCancel) = vbCancel Then
Exit Sub
End If
Else
Form_frmMainForm.Text2.SetFocus
End If

Any help is greatly appreciated and thank you in advance.
 
If IsNull(Form_frmMainForm.Text2.Value) Or IsNull(Form_frmMainForm.Text4.Value) Then
If MsgBox("From and Thru Dates Cannot Be Blank", vbOKCancel) <> vbCancel Then
Form_frmMainForm.Text2.SetFocus
End If
Exit Sub
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Are you doing this on the current form? If so use the Me keyword in stead (I don't like the Form_formname notation, in stead I use forms("frmMainForm")("Text2").value or forms!frmMainForm!text2.value to reference controls on other forms).

To test for Null, use either the IsNull function, or for instance:

[tt]if trim$(me!text2.value & "") = "" then[/tt]

Roy-Vidar
 
Thank you both! I thought it was an easy fix, I just couldn't figure how to get from A to B.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top