Results 1 to 7 of 7
  1. #1
    Synergy.ron@gmail.com is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2020
    Location
    washington
    Posts
    126

    Question thump,thump,thump why?

    ...That's the sound of my head banging on my desk.....


    Ihave some vba code that is acting weird(or, is it I who is acting weird?) Anyway i amalso attaching my accdb file.
    This is a learning project for me, so anything you say is appreciated. thank you! Attachment 45558

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Lose the ()
    EDIT
    And it's Dim s3 As ...
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Now that I'm off my phone, some observations
    If auth = True Then << what if auth is null, treat as if False?

    Call GettSerial << don't need Call Statement. IMO, do yourself a favour and don't bother with it because:
    - if there are arguments to be passed they must be (enclosed)
    - if Call is omitted, the parentheses must not be used or it will raise an error
    - called function return value is discarded; could lose some hair over that one

    gettAuthCode(snum As Long) As String
    Dim snum As Long << you've already declared snum in the function parameter.

    getAuthCode(s3) As Long <<lose the As Long. You don't type the function return value in the function call. Also, don't use () if the function returns a value and you don't use it.
    getAuthCode s3 would pass s3 to the function and not use the return value
    myVar = getAuthCode(s3) would return the value to myVar, thus () is required.

    Msgbox (snum&", " & s3) << The parentheses with Call might have steered you into a (bad?) habit. In the past I have coded as Msgbox(param1, param2, etc) and raised an error because of the () and lack of assigning a return value. Tonight, I can't get it to error using your syntax, and this tells me that doing so is incorrect so I'm a bit stymied at the moment.

    Last but not least, please don't post pics of code. Copy and paste code within code tags (# on post toolbar).
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94
    Quote Originally Posted by Micron View Post
    Msgbox (snum&", " & s3) << The parentheses with Call might have steered you into a (bad?) habit. In the past I have coded as Msgbox(param1, param2, etc) and raised an error because of the () and lack of assigning a return value. Tonight, I can't get it to error using your syntax, and this tells me that doing so is incorrect so I'm a bit stymied at the moment.
    This. As a rookie Java programmer I called every function with () and it gave me a whole lot of trouble. Try to use them only when necessary.

    About the error, the description leads to believe the error comes from the line before the one you marked. As Micron said, you skipped a blank space so it's taking it as a declaration of a variable named dimS3, which is incorrect declaration outside a Type block, as you can read here.

    Also take into consideration every tip Micron gave, I wished I'd read them instead of learning them the hard way. And never declare function parameters again inside a function

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    I did figure out that if you use Msgbox(....) and don't return a value, it fails if you define the button(s) but works if you don't. Very odd, and given the documentation on it, I'd call it a bug.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Synergy.ron@gmail.com is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2020
    Location
    washington
    Posts
    126
    Thanks to all for your thoughts. the common theme re) holds as do your other ideas. For what it's worth, hearing /reading about Access eccentricities helps A LOT!

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Didn't see project attached.
    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.

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

Tags for this Thread

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