Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,970
    As noted in post 14, % wildcard works in the ADO recordset SQL. And I read something today that says % is used in ADO.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  2. #17
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,992
    Hi June
    Its not quite as simple as that.
    See for example: https://access-programmers.co.uk/for...d.php?t=262327

    Of course, DAO code is far simpler to use and I still see no reason for using ADO here instead of DAO.
    In fact I see no reason to use the TableRead function at all - though I haven't had time to study the new code in post 13
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #18
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    This refers to the code posted in Post #13

    In "Function CStatus", there is a line
    Code:
    Dim strPreamble, strOut, strType, strForm, strComment, strSQL, strPxStack, strCErrStack As String
    The variable "strCErrStack" is declared as a string; all other variables default to Variant type.
    In VBA, variables MUST be explicitly declared. (EDIT: What orange said in Post #10)


    At the bottom of the code, there are lines
    Code:
    DoCmd.SetWarnings (warningsoff)
    DoCmd.RunSQL strSQL
    DoCmd.SetWarnings (warningson)
    Exit Function
    "warningsoff" and "warningson" are not declared and they are not intrinsic constants (so there must not be a line "Option Explicit" at the top of the module - otherwise you would get a compile error).

    Since "warningsoff" and "warningson" are not declared and "Option Explicit" has not been set, the two variables default to a value of 0 (zero).
    So both DoCmd.SetWarnings lines set the warnings to Off/False.



    The correct syntax, per Access, is
    Code:
    DoCmd.SetWarnings False
    
    DoCmd.RunSQL strSQL
    
    DoCmd.SetWarnings True
    Generally it is best to use:
    Code:
    Currentdb.Execute strSQL, dbfailonerror
    as this won't trigger a message and also won't turn off all the system messages as the DoCmd.SetWarnings will do after a failing query!
    Last edited by ssanfu; 01-03-2019 at 06:26 PM.

  4. #19
    MLogue9 is offline Novice
    Windows 8 Access 2007
    Join Date
    Jan 2019
    Posts
    22
    ridders52, Sorry I did not see that post. I may not be understanding the database functions correctly as I am a bit rusty. There isn't a function like tableRead where you can get a datum like foo = tableRead(...). Instead you need to define a connection and open and close it. It's slower, but easier to use, in my opinion. There problably is a better way.

    I used the immediate window for fact it is immediate. I wanted to test it quickly without adding code I'd dispose later.

    I tried using *, it doesn't work as a wildcard. I get no results. So I switched all back to %, which screwed up my multiplication operators too .

    -----------
    June7 - TableRead returns whatever single datum you tell it to. Hence purpose of intRow. But ridders52 has suggested it as redundant. We both know it's slow, because each iteration of it has to open and close connections. ...If the connection is left open, any code saying to open it will error. SAME goes for closed connections. I couldn't figure a way to test it without throwing errors, so I have the open and close within 3 lines in tableread.


    I have several modules, tableread is in one. The code I presented that is a mile long is in a Access Class Object for the respective form, fclips. Do I need to declare a variable passed through many of these at top of each or a single module?

  5. #20
    MLogue9 is offline Novice
    Windows 8 Access 2007
    Join Date
    Jan 2019
    Posts
    22
    ssanfu



    I had no IDEA in VBA declaration worked like that. I must have a hundred or so strings of declarations that go "one, two, three AS integer". I best get to replacing them although I haven't had a bunch of errors.

    Thanks for correcting me on system warnings syntax. True and false make more sense and I don't know what made me use warningson and warningsoff.

  6. #21
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,992
    I used the immediate window for fact it is immediate. I wanted to test it quickly without adding code I'd dispose later.
    I agree with that & often use the immediate window for the same reason. I would have written:
    Code:
    ?tableread("DirectSQL","SELECT COUNT(filesize) from tclips WHERE [filename] LIKE 'c151%';",0,0,0)
    However, using a sub is useful if you want to try out various values

    I must be missing something but I still can't see why you are using a function that is VERY slow and doesn't seem to work properly ... yet you call it 'lovely'!
    I gave two alternative approaches to counting records in post 11.

    Both are simple to code, run quickly (if using indexed fields) and don't require the use of recordsets.
    If you need to use wildcards, * will definitely work in those cases.

    Have you tried just running this as a query?
    Code:
    SELECT COUNT(filesize) from tclips WHERE [filename] LIKE 'c151%';
    OR it should then be
    Code:
    SELECT COUNT(filesize) from tclips WHERE [filename] LIKE 'c151*';
    However, I doubt I'm going to persuade you to change your approach at this stage
    I've asked before why you are using ADO rather than DAO
    DAO is simpler to code and more powerful ... so what is special about your code that requires the use of ADO?

    Good luck with solving your problem
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #22
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Some comments on the code for "Function tableRead"

    It is very rare to use the "GOTO" statement. In the IBM BASIC days, it resulted in very messy code that actually had a name: Spaghetti code.
    The command is still in VBA for backward compatibility.

    Here are two instances with changed code to eliminate the GOTO command:
    (1)
    Click image for larger version. 

Name:	Code1.png 
Views:	8 
Size:	51.8 KB 
ID:	36783

    and ----------------------------------------------------------------------------------------------
    (2)
    Click image for larger version. 

Name:	Code2.png 
Views:	9 
Size:	23.9 KB 
ID:	36784


    The last part of code I have comments on is
    Code:
        rs.Close
        Set rs = Nothing
        cn4.Close
        Set cn4 = Nothing
        If (vRows(0, intRow) = Null) Then vRows(0, intRow) = -1
        tableRead = vRows(0, intRow)
    IMHO, using the single line syntax of the IF statement is just plain lazy and makes code harder to read compared to the block form syntax.

    Block form
    Code:
        rs.Close
        Set rs = Nothing
        cn4.Close
        Set cn4 = Nothing
        If (vRows(0, intRow) = Null) Then
            vRows(0, intRow) = -1
        End If
        tableRead = vRows(0, intRow)
    With the block form syntax it is easier to see the problem..... which is
    Code:
       If (vRows(0, intRow) = Null) Then
    The problem is that you cannot check for NULLs this way.
    NULL is not equal to anything, not even NULL!
    You must use the IsNull() function.
    Code:
       If IsNull(vRows(0, intRow)) Then
    (or you could use If Len((vRows(0, intRow) & "")) > 0 Then )


    Note: you can test this by going to the immediate window in the IDE and entering
    ? 1=1

    then try
    ? null = 1


    Next try
    ? mull = null

    Use
    Code:
        rs.Close
        Set rs = Nothing
        cn4.Close
        Set cn4 = Nothing
        If IsNull(vRows(0, intRow)) Then
            vRows(0, intRow) = -1
        End If
        tableRead = vRows(0, intRow)

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 02-01-2018, 08:46 AM
  2. Access Runtime hangs on startup
    By Beltai in forum Access
    Replies: 0
    Last Post: 09-08-2017, 04:11 AM
  3. Access Hangs While Scrolling Columns
    By Micron in forum Access
    Replies: 3
    Last Post: 05-29-2015, 10:38 AM
  4. Module executes but then Hangs Access
    By Nishy in forum Modules
    Replies: 4
    Last Post: 02-24-2014, 06:11 PM
  5. Access front end hangs when more than one user
    By mafrank101 in forum Access
    Replies: 3
    Last Post: 05-31-2012, 10:15 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