Results 1 to 11 of 11
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    What does the # mean in the front of a statement?

    I'm running into more and more code samples that look something like this:
    Code:
    #Const Access_EarlyBind = True
    #If Access_EarlyBind = True Then
        Private pAccess                As Access.Application
    #Else
        Private pAccess                As Object
    #End If
    But I have no idea what the "#" is supposed to do. I haven't seen it documented or given a name so I can search for an explanation.


    What does it mean or do?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    https://www.google.com/search?q=acce...t=gws-wiz-serp

    And if you ask ChatGPT, see the picture. :-) rofl.

    Click image for larger version. 

Name:	Con Compile.JPG 
Views:	35 
Size:	92.6 KB 
ID:	51576
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    So the answer is, it's a thing called Conditional Compiling:
    Understanding conditional compilation (VBA) | Microsoft Learn

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by twgonder View Post
    So the answer is, it's a thing called Conditional Compiling:
    Understanding conditional compilation (VBA) | Microsoft Learn
    Correct. As in your example, whether you wish to enable early or late binding.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    ChatGPT is wrong.

    A '#' cannot be used at the start of a line to denote a comment. If you try to do so, the line will be marked as incorrect syntax in RED.
    Only apostrophes can be used for this purpose as in the example it gave

    It IS used for conditional compilation and as here for specifying early/late binding

    Code:
    '#Const EarlyBind = True     'Use Early Binding
    #Const EarlyBind = False    'Use Late Binding
    Click image for larger version. 

Name:	Capture.PNG 
Views:	28 
Size:	45.3 KB 
ID:	51577
    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

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I did not know you could tell it that is was wrong.
    I knew it was wrong which is why I was rofl.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Amicron's Avatar
    Amicron is offline Access Guru
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Amherst, New York (near Buffalo)
    Posts
    31
    GPT is often wrong. Always double check what it tells you.

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    did not know you could tell it that is was wrong
    if you tell it the solution it remembers, at least in the context of the sane conversation.

    i was doing some investigation of addressof and it provided examples where the target sub was in the class module. When I told it the sub had to be in a standard module it apologised and provided a correct example, and continues to do so.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    So what if you were to tell it something that was also wrong?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    I’m never wrong, just misunderstood 😁😁😁

  11. #11
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    I've deliberately asked it questions I know the answer to and it gets them wrong about 75% of the time.
    As stated, it will take into account any corrections it is given but will often still make more mistakes

    I've also deliberately fed it incorrect information which it also accepted.
    In my opinion Chat GPT is better at analysing than it is at providing correct code

    Perhaps it should use a strapline like mine (see below)!
    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

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

Similar Threads

  1. Replies: 3
    Last Post: 08-30-2023, 04:51 AM
  2. Replies: 11
    Last Post: 04-29-2015, 01:38 PM
  3. Front End
    By rosscortb in forum SQL Server
    Replies: 3
    Last Post: 03-06-2015, 02:54 PM
  4. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  5. Replies: 7
    Last Post: 08-17-2011, 01:49 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