Results 1 to 4 of 4
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Simple passing into function question

    I have a function (to string) that pulls in two controls from a form.

    These are combo boxes and it pulls in the ID field as int (not long as it's never going to be over 300)

    I have Public Function SearchArea(year As Integer, Area As Integer) As String

    however if the control is null I don't want the function to react however it doesn't like null and I get an error.

    In general how should I handle this if it is null.

    Should I when using the function say

    strWhere = searcharea(nz(me.cboYear,0),nz(me.cboyear,0)) ?

    however this would give me a numeric 0 to have to deal with in the function

    is there a way around?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    If you change Integer to Variant the parameters will take a Null, which can test for in your function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by pbaldy View Post
    If you change Integer to Variant the parameters will take a Null, which can test for in your function.
    That works, but is that the preferred method?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Generally I would prefer to handle the Null in the function rather than have to remember to account for it everywhere I may call that function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 4
    Last Post: 05-25-2014, 02:01 AM
  2. VBA passing rs! into function
    By Ruegen in forum Programming
    Replies: 15
    Last Post: 03-17-2014, 04:01 PM
  3. a simple getter function for a constant
    By veloopity in forum Programming
    Replies: 10
    Last Post: 10-19-2013, 12:17 PM
  4. Replies: 11
    Last Post: 05-17-2013, 06:10 AM
  5. Need Help with Simple VB Function
    By nrage21 in forum Programming
    Replies: 2
    Last Post: 09-21-2010, 09:14 AM

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