How to clear the contents of a text box? (1 Viewer)

joner89

Registered User.
Local time
Today, 17:41
Joined
Nov 15, 2010
Messages
30
I have two boxes, one contains an order date and one contains a required date. I have code that compares these so if the required date is earlier than the order date an error message shows. If this occurs then i want some code to clear the two boxes ready for new dates to be entered. Here is my attempt so far.

Code:
Private Sub Command43_Click()
If Me.DateRequired.Value < Me.OrderDate.Value Then
MsgBox "The date required is earlier than the date ordered" & vbCrLf & _
"Please select a date required later than the date ordered"
Me.DateRequired.Value.Refresh
Me.OrderDate.Value.Refresh
End If
End Sub



When i try the Me.DateRequired.Value.Refresh it comes up with the error 'object required'. Anyone know why this is happening ands how to acheive what i need?

Thanks in advance!
 

boblarson

Smeghead
Local time
Today, 09:41
Joined
Jan 12, 2001
Messages
32,059
something like this:
Code:
Me.DateRequired = Null
Me.OrderDate = Null

or

Code:
Me.DateRequired = ""
Me.OrderDate = ""
 

smig

Registered User.
Local time
Today, 19:41
Joined
Nov 25, 2009
Messages
2,209
why won't you test this using the AfterUpdate event of the boxes, preventing the user having wrong dates?

you can use the validation rule of each field to compare it to the other one.
 

vbaInet

AWF VIP
Local time
Today, 17:41
Joined
Jan 22, 2010
Messages
26,374
why won't you test this using the AfterUpdate event of the boxes, preventing the user having wrong dates?

you can use the validation rule of each field to compare it to the other one.
Good point but I think you mean the Before Update event. However, this still won't clear the textbox which is what is being asked.
 

spikepl

Eledittingent Beliped
Local time
Today, 18:41
Joined
Nov 3, 2010
Messages
6,142
Anothe issue is reading the messages that Access generates: 'object required' means that the Refresh method wants an object to play with but is not getting one. Check the offending statement, and try to think why.
 

vbaInet

AWF VIP
Local time
Today, 17:41
Joined
Jan 22, 2010
Messages
26,374
Anothe issue is reading the messages that Access generates: 'object required' means that the Refresh method wants an object to play with but is not getting one. Check the offending statement, and try to think why.
Me.DateRequired.Value.Refresh is not a valid statement. There's no associated Refresh method or property of the Value property.
 

spikepl

Eledittingent Beliped
Local time
Today, 18:41
Joined
Nov 3, 2010
Messages
6,142
I know that. You know that. OP did not know that, and I was trying to kickstart OP's understanding of the messages.
 

Users who are viewing this thread

Top Bottom