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. Anonymous
    2020-07-02T08:49:30+00:00

    You can replace the weird code with something much simpler and cleaner:

    Private Sub Form_Load()

        ' Assign today's date to the combo.

        ' Only makes sense, if the source for the combobox includes this date.

        Me!cboDate.Value = Date

        ' Store the record.

        Call LoadData

    End Sub

    Public Function LoadData()

        Dim Sql As String

        Sql = "Insert Into Food_Distribution (fd_date, first_name, last_name, gender) " & _ 

            "Select Date(), first_name, last_name, gender From tblFD;)"

        CurrentDb.Execute Sql

    End Function

    0 comments No comments
  2. Anonymous
    2020-07-02T10:26:15+00:00

    Hi there

    Thank you for your help. Your function is working but when ever I open form it is add another set of the same records for that day. I need solution to append records to Food_Distribution only  once per day. Why: We take tablet to the kitchen for the breakfast and after breakfast we close form Food Distribution. For the lunch if we open again I want that records to continue to record for the lunch. Three meals have check box which we check for every ID. So lets summarize, when I open form I do not want the same records to be appended to the table. Only when next day we open form than for that day records should be saved to table. Thank yoy

    0 comments No comments
  3. Anonymous
    2020-07-02T10:40:12+00:00

    You are right. Missed that detail.

    This should take of that:

    Public Function LoadData()

        Dim Sql As String

        If IsNull(DLookup("fd_date", "Food_Distribution", "fd_date = Date())) Then

            Sql = "Insert Into Food_Distribution (fd_date, first_name, last_name, gender) " & _ 

                "Select Date(), first_name, last_name, gender From tblFD;)"

            CurrentDb.Execute Sql

        End If

    End Function

    0 comments No comments
  4. Anonymous
    2020-07-02T14:18:48+00:00

    Hi

    I wrote your code and getting error in the line:

     If IsNull(DLookup("fd_date", "Food_Distribution", "fd_date = Date())) Then

    When I write it like this the everything is ok:

     If IsNull(DLookup("fd_date", "Food_Distribution", FD_Date = Date)) Then

    Could you please help maybe I am missing something.

    Thanks

    0 comments No comments