Results 1 to 4 of 4
  1. #1
    DubCap01 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Location
    Dubbo, Australia
    Posts
    104

    Nullifying a field's contents


    Hi all,

    is there an alternative to making a field blank, other than my old trusty <Me.Field1 =""> ... ?
    (my use of the < and > are purely for demonstration purposes, and do NOT get used in code)

    I'd like some fields to be native, virgin, blank, et cetera... I do find sometimes I have to overly complicate a VBA statement by putting.. <If IsNull(Me.Field1) or Me.Field1 = "" then> because I have made that field value = "" to blank it out.

    thanks in anticipation
    Pete

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Since there is not a built in IsNothing() function I use a custom function to check if a value is 0 or False or empty or Nothing, etc.

    I simply pass the variable as an argument to the function. The function uses a Case Select statement to consider the variable type, using the VarType Function.
    https://msdn.microsoft.com/en-us/lib.../gg278470.aspx

    I can pass a variable I declared or an object like a textbox control.

    Having said that, with newer versions of Access, I have not been able to store an empty string in a table. I think I have been able to store an empty string in a control. However, after the form is refreshed, it is returned to a Null state.

  3. #3
    DubCap01 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Location
    Dubbo, Australia
    Posts
    104
    Thanks ItsMe,

    The answer to my question about the code goes from:
    If IsNull(Me.Field1) or Me.Field1 = ""

    to
    Me.Field1= vbEmpty

    simple, but magic, thanks mate! And, for other readers, a great link!

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The reason I linked to that page is because it describes the constants associated with the VarType Function. If you determine the type of the variable you can determine what you need to test for. For instance, if the variable type is a Boolean, you can test for 0. If the type is text or string you can test for Null and "", etc.

    I would post the function I use here if I did not copy it from a book over a decade ago. It is rather simple and there is no real good way to rewrite it. You test for the variable type and then use a Select Case statement to test for 0 or "" or whatever.

    What you have here
    Me.Field1= vbEmpty

    Is the same as assigning 0 to Field1
    Me.Field1= 0

    So, you will need to rethink your approach.

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

Similar Threads

  1. Replies: 2
    Last Post: 07-28-2013, 04:52 PM
  2. Replies: 11
    Last Post: 07-05-2013, 08:00 AM
  3. Replies: 5
    Last Post: 04-18-2012, 12:04 PM
  4. Replies: 3
    Last Post: 05-23-2011, 07:29 AM
  5. Replies: 0
    Last Post: 03-29-2011, 04:11 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