|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
type mismatch in VBA SELECT statement
I have the following code:
Code:
Dim stRecordSet As String
Dim strMonthYear As String
strMonthYear = InputBox("Please Enter Desired Month and Year in the following format: 2/2005")
If strMonthYear > "" Then
stRecordSet = "SELECT Case_Number_VC, Case_Short_Name_VC, Received_DT, Date, Notes, Description, Case_Type_VC FROM dbo.MED_RPT_Cases_Reviewed_V" _
& " WHERE DatePart(Date, m & " / "&yyyy) ='" & strMonthYear & "'"
Me.RecordSource = stRecordSet
Else
DoCmd.CancelEvent
End If
I keep getting a type mismatch on the select statement. I did try changing the strMonthYear to a DATE type, but then I get a type mismatch on the If/Then statement. I'm using VBA for Access 2003. Thanks for any help! |
|
#2
|
||||
|
||||
|
i believe 'date' is a reserved word ... try this:
Code:
stRecordSet = "SELECT [Case_Number_VC], [Case_Short_Name_VC], [Received_DT], [Date], [Notes], [Description], [Case_Type_VC] FROM dbo.MED_RPT_Cases_Reviewed_V WHERE DatePart(Date, m & " / "&yyyy) ='" & strMonthYear & "'"
__________________
Come JOIN the party!!! Quote of the Month: Retirement: Because you've given so much of yourself to the company that you don't have anything left we can use. Questions to Ponder: What do you do when you see an endangered animal eating an endangered plant? iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm") copyright© 2008 sbenj69 |
|
#3
|
|||
|
|||
|
Okay - I tried that and still got the same error. And then I changed the field name in the query to avoid using "date" at all.
Code:
stRecordSet = "SELECT Case_Number_VC, Case_Short_Name_VC, Received_DT, StatusDate, Notes, Description, Case_Type_VC FROM dbo.MED_RPT_Cases_Reviewed_V" _
& " WHERE DatePart(StatusDate, m & " / "&yyyy) ='" & strMonthYear & "'"
I still get the same error. I think the problem must be with my DatePart expression - does that look right? |
|
#4
|
||||
|
||||
|
try something like this:
Code:
vArray = split(strMonthYear, "/") stRecordSet = "SELECT Case_Number_VC, Case_Short_Name_VC, Received_DT, StatusDate, Notes, Description, Case_Type_VC FROM dbo.MED_RPT_Cases_Reviewed_V WHERE Month(StatusDate) = '" & vArray(0) & "' AND Year(StatusDate) = '" & vArray(1) & "'" |
|
#5
|
|||
|
|||
|
Perfect - thanks!
|
|
#6
|
||||
|
||||
|
good ... glad it worked for you ...
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > type mismatch in VBA SELECT statement |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|