Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,556 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,902 people online right now. Registration is fast and FREE... Join Now!




VBA

 
Reply to this topicStart new topic

VBA

Jman08
7 Apr, 2008 - 06:50 AM
Post #1

New D.I.C Head
*

Joined: 27 Mar, 2008
Posts: 5

Hi All

I have an access database and I'm using VBA.

I've got a form that allows a user to input a first hire date, and another last date of hire.

I'm trying a VBA if statement to stop users from putting in a value in the end date less then the first hire date.

For example First Date Hire: 1/04/08 End Date hire:31/03/2008.

The code I have got is
CODE

Private Sub btn_Refresh_Click()
If txb_Start_Date.Value < txb_End_Date.Value Then
txb_End_Date.SetFocus
MsgBox ("Bla")
End If


Me.frm_CarsAvailable.Requery ' if the date is fine then I want it to carry on with this..

End Sub


But nothing happens. Anyone able to help me?, also can VBA display a message if a subform has no search results it (like a blank table?)
User is offlineProfile CardPM
+Quote Post

Jman08
RE: VBA
7 Apr, 2008 - 07:36 AM
Post #2

New D.I.C Head
*

Joined: 27 Mar, 2008
Posts: 5

lol, nevermind.. got it working used > instead of < my bad! =p

oh, can vba display a message if a subreport returned no value?, I'm not sure how I would do that.

Actaully I've got it half working, just tried to stop the program refreshing the list and it gives an error if I put an End Sub.

CODE

Private Sub btn_Refresh_Click()
If txb_Start_Date.Value > txb_End_Date.Value Then
txb_End_Date.SetFocus
MsgBox ("Error.The End Date Should Not Be Less Then The Start Date. Please Change The End Date.")
End Sub - I'm trying to stop the program so the user must change the end date.
Else

Me.frm_CarsAvailable.Requery
End If
End Sub


This post has been edited by Jman08: 7 Apr, 2008 - 07:40 AM
User is offlineProfile CardPM
+Quote Post

KG87
RE: VBA
9 Apr, 2008 - 10:18 AM
Post #3

D.I.C Head
**

Joined: 25 Sep, 2007
Posts: 52



Thanked: 2 times
My Contributions
Just a quick one from me, that End sub wants to be

Exit sub


Its like this



If txb_Start_Date.Value > txb_End_Date.Value Then
txb_End_Date.SetFocus
MsgBox ("Error.The End Date Should Not Be Less Then The Start Date. Please Change The End Date.")


Exit Sub
Else

Me.frm_CarsAvailable.Requery
End If
End Sub
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:19PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month