Results 1 to 4 of 4
  1. #1
    Njliven is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    86

    Fill in Field base on Value of Another

    Here is the code I am trying to use and it does not work. I have tried using it in the On Exit and On Lost Focus. No errors just nothing happens.



    I also tried the IsNull = true or false then I get a compile error that say argument is not optional.
    What am I doing wrong. Should I be using the code some place else.


    If [ExpireDate] = "" Then
    [Inactive] = "Inactive"


    ElseIf [ExpireDate] > Now Then
    [Inactive] = ""
    End If


    Thanks for any help.

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    First off, to test whether or not a Control has been left blank (Null) you need to use the Form_BeforeUpdate event. Using the OnExit or LostFocus event of the Control is useless for this; to defeat the testing the user merely has to not bother to enter the Control.

    Also, you need to check for Null, as well as a Zero-Length String ("".) There are a number of ways to do this...everyone has a favorite. For this I would generally use

    If Nz(Me.ExpireDate, "") = "" Then

    This should do what you need:

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
     
     If Nz(Me.ExpireDate, "") = "" Then
      Me.Inactive = "Inactive"
     End If
    
    If Me.ExpireDate > Date Then
     Me.Inactive = Null
    End If
    
    End Sub

    Linq ;0)>

  3. #3
    Njliven is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    86
    Quote Originally Posted by Missinglinq View Post
    First off, to test whether or not a Control has been left blank (Null) you need to use the Form_BeforeUpdate event. Using the OnExit or LostFocus event of the Control is useless for this; to defeat the testing the user merely has to not bother to enter the Control.

    Also, you need to check for Null, as well as a Zero-Length String ("".) There are a number of ways to do this...everyone has a favorite. For this I would generally use

    If Nz(Me.ExpireDate, "") = "" Then

    This should do what you need:

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
     
     If Nz(Me.ExpireDate, "") = "" Then
      Me.Inactive = "Inactive"
     End If
    
    If Me.ExpireDate > Date Then
     Me.Inactive = Null
    End If
    
    End Sub

    Linq ;0)>




    Works! Thanks

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad we could help!

    Linq ;0)>

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Delete Query base on Min date value in field
    By ui7598h in forum Queries
    Replies: 1
    Last Post: 03-18-2015, 02:43 PM
  2. Replies: 11
    Last Post: 07-05-2013, 08:00 AM
  3. Format field base on entered data
    By survivo01 in forum Forms
    Replies: 3
    Last Post: 10-26-2012, 02:48 PM
  4. Replies: 1
    Last Post: 08-18-2012, 11:32 PM
  5. Totaling Record base on ID and amount field
    By boywonder in forum Access
    Replies: 3
    Last Post: 11-25-2011, 03:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums