0

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)
Paul T.
  • 4,703
  • 11
  • 25
  • 29
Salim
  • 11
  • 1
  • 5
  • Remove the `;` after `Wyr2` and `Wyr3`. – Paul T. Dec 02 '20 at 02:39
  • I did this already and thats doesnt work. – Salim Dec 02 '20 at 22:02
  • 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 Dec 02 '20 at 22:05
  • Can your format the date to get: `#01/12/2020#`. That is based on examples [found here](https://support.microsoft.com/en-us/office/examples-of-using-dates-as-criteria-in-access-queries-aea83b3b-46eb-43dd-8689-5fc961f21762#__toc358028377). I'll also add the ms-access tag, might attract more users. – Paul T. Dec 03 '20 at 00:39
  • Yea its actually my first code ? :) I am earning vba and sql also its my first time in this portal :) – Salim Dec 03 '20 at 13:09
  • i will try to find something about this – Salim Dec 03 '20 at 13:10

1 Answers1

0

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.

Gustav
  • 53,498
  • 7
  • 29
  • 55
  • Then are inserting data that don't match your table. Print out the SQL and run it manually to debug. – Gustav Dec 03 '20 at 19:00