you can also add this code to your form:
on design view of your Form, add this to the After Update Event (Property) of [col1] to [col3]:Code:Public Function fnCombosToTime() Dim dte As Date Me![Appt Time] = CDate(Nz([col1],0) & ":" & Nz([col2],0) & " " & Nz([col3],"AM")) End Function
Code:=fnCombosToTime()
I Get A Compile Error "Expected line number or label or statement or end of statement"
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.
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.
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
toCode:Me.COL1 = "": Me.COL2 = "": Me.COL3 = ""
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
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
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.
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.
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.
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
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.