Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 30th, 2006, 03:43 PM
Registered User
 
Join Date: Jun 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Validating Forms Problems

I am new to the VBA world. I have a form that I am trying to validate the fields on. They are either text boxes or combo boxes. I have a custom function that is called when the user clicks a command button. I cannot test any of these fields for no user input or null. None of these work:

If (Me.txtProductCode = Null) Then
  ' some code here
End if

or

If Len (Me.txtProductCode) = Null Then
  ' some code here
End if
or

If Len(Me.txtProductCode) = 0 Then
  ' some code here
End if

If IsNull(Me.txtProductCode) = True Then
  ' some code here
End if

I have tried to use the expression builder but it is very confusing for me. I'd rather do this in VB code. So, how do you check the contents of form fields in VB? Where is there some very good examples of this? Thanks

[email protected]
 
Old July 1st, 2006, 06:16 AM
Authorized User
 
Join Date: May 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Ashfaque
Default

Try following :

If Len(Me.txtProductCode) > 0 Then
  ' some code here
End if

Regards,
Ashfaque

 
Old July 3rd, 2006, 07:30 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I generally use the simple form:

If IsNull(Me.txtProductCode) Or Me.txtProductCode = "" Then
  ' some code here
End if

You can't test for null After you take a control value, so (Me.txtProductCode) = Null won't work (in Jet.) You have to tell Jet you are going to check for a Null value first IsNull() or else Jet will throw a fit when it hits the = sign, because Null values are not equal to anything.

Optionally, you can enforce this sort of issue at the table design level if the form is based on a table by making the fields required, and having some validation rule there, rather than in the form.

HTH

mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with MDI Forms danielkelly C# 4 December 22nd, 2008 11:39 PM
validating Login Forms hanumanth.sr ADO.NET 1 April 19th, 2006 02:34 PM
Problems with Inherited Forms in VC# mmwaikar VS.NET 2002/2003 2 July 20th, 2005 10:01 AM
Problems at Using CRViewer for Web-Forms (VB.NET) vblover Crystal Reports 1 August 27th, 2004 10:38 AM
Help! problems with functions and forms Toka1 Javascript How-To 6 December 16th, 2003 11:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.