0
votes

I wrote this code. When I try to activate this sub I always get this problem "syntax error (missing operator) in query expression '2020-12-01'". It's something wrong with Date (data in Polish means date).

Could u help me to fix this ?? I just want to take "Kolejka", "stadion", "Data" from form and add to my table Rozgrywki. I also attached pictures of this error and picture of my form in access.

Runtime error "3075"
Dialog being composed

 Public Sub Dodaj(Kolejka, stadion, Data, DA, DB, Optional wa = 0, Optional wb = 0)
    If [wa] = "" Then wa = 0
    If [wb] = "" Then wb = 0
    DoCmd.SetWarnings False
    dodaj_rozgrywka = "" & _
            "INSERT INTO Rozgrywki ( IDStadionu, Data, Idkolejki)" & _
            "SELECT " & stadion & " AS Wyr1, #" & Data & "# AS Wyr2;, " & Kolejka & " AS Wyr3;"
    DoCmd.RunSQL (dodaj_rozgrywka)
1
Remove the ; after Wyr2 and Wyr3.Paul T.
I did this already and thats doesnt work.Salim
I gues its something wrong with access. I dont may be should i change date format. May be u could code for the change of date format ??Salim
Can your format the date to get: #01/12/2020#. That is based on examples found here. I'll also add the ms-access tag, might attract more users.Paul T.
Yea its actually my first code ? :) I am earning vba and sql also its my first time in this portal :)Salim

1 Answers

0
votes

Format your date value to a string expression:

"SELECT " & stadion & " AS Wyr1, #" & Format(Data, "yyyy\/mm\/dd") & "# AS Wyr2;, " & Kolejka & " AS Wyr3;"

Or use my CSql function. Even better, learn yourself to use queries with parameters.