disgracept
Member
- Local time
- Today, 09:16
- Joined
- Jan 27, 2020
- Messages
- 45
Hi all.
I'm having a problem that is getting me nuts...
I have a form to make updates to my tables that has a tab control with several pages. Each page is for a specific update.
Then i made this sub to update the corresponding fields of the tables:
This is supposed to run the sql in the commented line, but for now i just set the querydef of Query1 to show whats happening.
When a textbox has a date and the day number is less then the month number (for example 04/12/2023) the result query swaps the day with the month and i get 12/04/2023 as you can see in the image below...
But the mySQL variable holds the correct value:
And the SQL of the query also has the correct value:
But it inserts in the table the incorrect one...
And i can't figure why this happens... All the date formats are correct and set to "Short date" with the format of my system - dd/mm/yyyy.
What is happening and how can i solve this?
Thanks in advance for the help.
I'm having a problem that is getting me nuts...
I have a form to make updates to my tables that has a tab control with several pages. Each page is for a specific update.
Then i made this sub to update the corresponding fields of the tables:
Code:
Private Sub updateImovel(myTable As String, myPage As String, maxCtrl As Integer)
Dim mySQL As String
Dim db As DAO.Database
Set db = CurrentDb
Dim qdf As DAO.QueryDef
Dim currChk As Control
Dim currCtrl As Control
Dim currIndx As Integer
Dim firstUpd As Boolean
firstUpd = True
mySQL = "UPDATE " & myTable & " SET "
For currIndx = 1 To maxCtrl
Set currChk = Me.Controls("chk_" & myPage & "_" & currIndx)
If currChk Then
Set currCtrl = Me.Controls(currChk.Tag)
If firstUpd Then
firstUpd = False
Else
mySQL = mySQL & ", "
End If
Dim textCtrl As String
If Nz(currCtrl, "") = "" Then
textCtrl = Chr(34) & Chr(34)
Else
If IsDate(currCtrl) Then
textCtrl = "#" & currCtrl & "#"
Else
textCtrl = currCtrl
End If
End If
mySQL = mySQL & myTable & "." & currCtrl.Tag & "=" & textCtrl
End If
Next
mySQL = mySQL & " WHERE (((" & myTable & ".Imovel_ID)=" & txt_Imovel_ID & "));"
MsgBox (mySQL)
DoCmd.SetWarnings False
'DoCmd.RunSQL mySQL
DoCmd.SetWarnings True
Set qdf = db.QueryDefs("Query1")
qdf.SQL = mySQL
Set qdf = Nothing
Set db = Nothing
End Sub
This is supposed to run the sql in the commented line, but for now i just set the querydef of Query1 to show whats happening.
When a textbox has a date and the day number is less then the month number (for example 04/12/2023) the result query swaps the day with the month and i get 12/04/2023 as you can see in the image below...
But the mySQL variable holds the correct value:
And the SQL of the query also has the correct value:
But it inserts in the table the incorrect one...
And i can't figure why this happens... All the date formats are correct and set to "Short date" with the format of my system - dd/mm/yyyy.
What is happening and how can i solve this?
Thanks in advance for the help.
Attachments
Last edited: