Syntax error in date in query expression #My_date=01.07.2020.#

Anonymous
2020-07-01T17:21:08+00:00

Hello

I have vba code on the unbound combo box in access but when I load the form I get syntax error in date. My date format is dd.mm.yyyy.

Please see attached screenshot. Could someone help with this error. Thank you.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2020-07-02T20:23:29+00:00

    Please notice, that a combobox can only hold text items, thus the first column will be FD_Date (or Date()) casted to text as to your regional settings of Windows.

    Also, I guess you wish to order by the date value, not the day. Then you would need a column like

    Format(Date(), "yyyymmdd")

    to order by.

    0 comments No comments

15 additional answers

Sort by: Most helpful
  1. Tom van Stiphout 40,091 Reputation points MVP Volunteer Moderator
    2020-07-01T17:45:47+00:00

    Date literals must be in US format: mm/dd/yyyy

    Write yourself a new function ToSqlDate, which takes a date parameter and returns a US-formatted date string.

    Then use it in your DCount expression.

    0 comments No comments
  2. Anonymous
    2020-07-01T18:26:37+00:00

    Thank you very much on quick reply.

    I am not a programmer and do not know how to write a new code. I hve found this code on the internet. Still learning access world. I would appreciate if you can help with this. I guess that regional settings should not be a problem but it is. Since I need date format for my region because of other applications.

    Thank you.

    0 comments No comments
  3. Anonymous
    2020-07-02T04:00:08+00:00

    Perhaps if you explain what it is you are trying to do we may be able to help. Much of what you have makes no sense (to me anyway). 

    me.cbodate=now() makes no sense. You might set a default value for a combo on load, which would be an integer, but not now()

    if dcount("1" .... 1 is a terrible name for a field.

    If your date is in fact a string then the syntax would be more like:

    If DCount("[1]", "Food_Distribution", "[FD_date] = '" & strdate & "'") > 0 Then

    but it would be strange to have a date in a table with a datatype of 'string'.

    What is the datatype of FD_date in table Food_Distribution?

    0 comments No comments
  4. Anonymous
    2020-07-02T08:05:02+00:00

    Hi 

    I have unbound form where is unbound combo box for date where on open sets Now() date. On the form I have sub form which is bounded to the table Food_Distribution. When I open form every day then on the subform takes data from tblFD where is ID_No, name, surname and gender and append that date for each ID and save it to  Food_Distribution. tblFD table is a temporary table which is loaded with other beneficiaries every day. Problem was the date which I cannot save in FD table because Food distribution takes place every day and cannot bound date field to a table. FD_Date is a date format dd.mm.yyyy. "1" is coming from the Date_Index table. So every day I get archived all beneficiaries data with a date of Food distribution. Hope this helps to get better picture. 

    Thank you any way for your help and explanation.

    0 comments No comments