Page 2 of 2 FirstFirst 12
Results 16 to 26 of 26
  1. #16
    westfallbp is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2021
    Posts
    26

    Get A compile ERROR

    Quote Originally Posted by jojowhite View Post
    you can also add this code to your form:



    Code:
    Public Function fnCombosToTime()
    Dim dte As Date
    Me![Appt Time] = CDate(Nz([col1],0) & ":" & Nz([col2],0) & " " & Nz([col3],"AM"))
    End Function
    on design view of your Form, add this to the After Update Event (Property) of [col1] to [col3]:

    Code:
    =fnCombosToTime()


    I Get A Compile Error "Expected line number or label or statement or end of statement"

  2. #17
    westfallbp is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2021
    Posts
    26
    Quote Originally Posted by westfallbp View Post
    I Get A Compile Error "Expected line number or label or statement or end of statement"

    Also, when I compile in module i get a compile error: "External name not defined"

  3. #18
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    444
    here is a demo. open demoForm on design view and see the code on each Combo's AfterUpdate event.
    see the code behind the the form.
    Attached Files Attached Files

  4. #19
    westfallbp is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2021
    Posts
    26
    CHU Ching, Exactly what I needed, I appreciate it very much. The last example I had the function in a module which is why it produced error I assume.

  5. #20
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,880
    Jojo,
    I think you need to adjust your code slightly.
    In your function you're testing for null but in your current event you're setting the combos to a ZLS. This throws an error on first selection.

    change
    Code:
    Me.COL1 = "": Me.COL2 = "": Me.COL3 = ""
    to
    Code:
    Me.COL1 = Null: Me.COL2 = Null: Me.COL3 = Null
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #21
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,575
    Quote Originally Posted by westfallbp View Post
    CHU Ching, Exactly what I needed, I appreciate it very much. The last example I had the function in a module which is why it produced error I assume.
    Well it did say add to form?
    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. #22
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Agree with Moke123 adjustment. I NEVER set anything to an empty string, always Null. I never allow empty string in fields.

    Westfallup, code in general module would fail because of the Me. reference.

    This could be modified to be a general function that could be called from anywhere but if you don't need anywhere else, done.
    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.

  8. #23
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    444
    i don't see any errors, you can test the db yourself if you wish.
    assigning SLZ or Null results to the combo not selecting any item
    on its list.

  9. #24
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Using Nz() when the value passed in is empty string does nothing, might as well not use.
    CDate() function will error if concatenation is with empty strings.
    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.

  10. #25
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    444
    Quote Originally Posted by June7 View Post
    Using Nz() when the value passed in is empty string does nothing, might as well not use.
    CDate() function will error if concatenation is with empty strings.
    then change the function to:
    Code:
    Public Function fnCombosToTime()
    Dim dte As Date
    Me![APPT TIME] = CDate(Val([COL1] & "") & ":" & Val([COL2] & "") & " " & IIf(Trim$([COL3] & "") = "", "AM", "PM"))
    End Function

  11. #26
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Yes, that allows for either ZLS or Null.
    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.

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

Similar Threads

  1. Access Date and Time Picker
    By jsimard in forum Queries
    Replies: 1
    Last Post: 01-24-2012, 04:04 PM
  2. Help with time picker
    By Nokia N93 in forum Access
    Replies: 1
    Last Post: 03-29-2011, 10:21 AM
  3. Time picker for Access 2003
    By Thiyagu in forum Access
    Replies: 1
    Last Post: 03-24-2010, 06:36 AM
  4. Access Runtime 2007 Date Time Picker Vista not working
    By sailinxtc in forum Programming
    Replies: 0
    Last Post: 09-17-2008, 12:56 PM
  5. Microsoft Date and Time Picker 6.0
    By That Crazy Hockey Dood in forum Forms
    Replies: 0
    Last Post: 07-25-2007, 03:22 PM

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