【发布时间】:2015-10-04 18:01:44
【问题描述】:
我在表单上使用 DatePicker 和文本字段供用户选择日期,默认情况下它在文本字段中显示为 dd/mm/yyyy。因此,当我编写代码时,我使用这种格式来保持一致。但是,当我保存像 2015 年 3 月 10 日(即 10 月 3 日)这样的日期时,它会保存为 3 月 10 日。鉴于以下代码,我需要更改哪些内容才能正确保存到数据库?
Private Sub cmdSave_Click()
...
Dim StartDate As String
Dim EndDate As String
Dim SDate As Date
Dim EDate As Date
...
StartDate = Me.txtStartDate.Value & " " & Me.txtStartTime.Value
EndDate = Me.txtEndDate.Value & " " & Me.txtEndTime.Value
SDate = CDate(Format(StartDate, "dd\/mm\/yyyy hh:mm"))
EDate = CDate(Format(EndDate, "dd\/mm\/yyyy hh:mm"))
If Me.txtOtherDetails.Value = "" Then
query1 = "INSERT INTO Shifts (Schedule_ID,Start_Date_Time,End_Date_Time,Location)" & _
" VALUES (" & ScheduleID & ",#" & SDate & "#,#" & EDate & "#," & LocationID & ")"
Else
query1 = "INSERT INTO Shifts (Schedule_ID,Start_Date_Time,End_Date_Time,Location,Other_Details)" & _
" VALUES (" & ScheduleID & ",#" & SDate & "#,#" & EDate & "#," & LocationID & ",'" & Me.txtOtherDetails.Value & "')"
End If
'Debug.Print query1
ShiftID = ExecuteInsert(query1)
End Sub
【问题讨论】:
标签: ms-access vba ms-access-2010 dao