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

    ADO recordset if null/0

    I'm working with recordset on a form however the user must first fill the date fields and then use a list button to list the records else there is nothing.



    I have another button that has an if with isnull(datefield1) or isnull(datefield2) to cover that however if there isn't anything in the recordset then I will get an error

    I have rs.movefirst and rs.movelast and then rs.recordcount to count the recordset

    I also have recordcount = rs.recordcount to hold the count for a message box (so the user can be warned as to how many records they will be emailing before the attempt it)

    I'd like to prevent any errors if the list is null/0

    how would I go about this in the proper way?

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Edit: I just realized you are using ADO. The rules a little different for ADO and I though you were using DAO


    Your isnull() function should do the job of determining wheather or not there is a value in the text field. You could add another validation for empty string

    if me.datefield = "" then

    For unbound textboxes, if the user deletes the value before continuing, it will no longer be null, it will be an empty string. This is also true for controls bound to certain field data types like text data types.

    As for validation of your recordset in your DAO. You can use the .EOF. You can also use the .Recordcount

    You do not need always need to .Movefirst or .Movelast. For instance, .Findfirst will populate a recordset. So you will not need to .Movelast and then .Findfirst.

    To get a recordcount you can

    Dim intCount as integer
    .MoveFirst
    intcount = .Recordcount
    msgbox intcount

    if intcount <=0 then
    set rs = nothing
    exit sub
    end if
    Last edited by ItsMe; 11-24-2013 at 04:28 PM. Reason: Just realized...

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by ItsMe View Post
    Edit: I just realized you are using ADO. The rules a little different for ADO and I though you were using DAO


    Your isnull() function should do the job of determining wheather or not there is a value in the text field. You could add another validation for empty string

    if me.datefield = "" then

    For unbound textboxes, if the user deletes the value before continuing, it will no longer be null, it will be an empty string. This is also true for controls bound to certain field data types like text data types.

    As for validation of your recordset in your DAO. You can use the .EOF. You can also use the .Recordcount

    You do not need always need to .Movefirst or .Movelast. For instance, .Findfirst will populate a recordset. So you will not need to .Movelast and then .Findfirst.

    To get a recordcount you can

    Dim intCount as integer
    .MoveFirst
    intcount = .Recordcount
    msgbox intcount

    if intcount <=0 then
    set rs = nothing
    exit sub
    end if

    Arghh! my mistake! I meant DAO - I apologise!! But otherwise good to know *I still need to learn all this anyway

    I went and got a morning coffee after this**

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Thanks for your help itsme

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

Similar Threads

  1. Replies: 3
    Last Post: 11-13-2013, 08:56 AM
  2. ignoring null value in recordset
    By nickblitz in forum Access
    Replies: 10
    Last Post: 11-16-2012, 02:38 AM
  3. Replies: 2
    Last Post: 03-08-2012, 12:59 PM
  4. Replies: 0
    Last Post: 12-14-2009, 04:55 PM
  5. Replies: 1
    Last Post: 11-13-2009, 03:03 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