![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
On Jan 27, 10:22*pm, Marshall Barton <marshbar... (AT) wowway (DOT) com> wrote: PW wrote: On Wed, 26 Jan 2011 12:48:45 -0800 (PST), XPS350 <xps... (AT) gmail (DOT) com wrote: On 26 jan, 21:14, PW <emailaddyin... (AT) ifIremember (DOT) com> wrote: Dim intYear1 As Integer Dim intYear2 As Integer intYear1 = Me.txtYear intYear2 = intYear1 - 1 Set db = CurrentDb() Set rstSuppressList = db.OpenRecordset("Select * From tblReservations Where Year([date_arriv]) = & intYear1 Or year([date_arriv]) = & intYear2 ") With the above I am getting an error "can't find the field '|' referred to in your expression" with the above statement. intYear(2011) is an integer as is intYear2. date_arriv is a date field in table tblReservations. How do I get the OR statement to work in this case? I want all records where the year is 2011 or 2010 in this instance. What am I doing wrong? I need the " at the end of the Select statement, right? I have fooled around with various combinations and can't get it to work. Any ideas? -paulw Because intYear1 and intYear2 are variables they should not be included in a string between " ". Try: "Select * From tblReservations Where Year([date_arriv]) =" & intYear1 & " Or year([date_arriv]) =" & intYear2) Now I have to add another OR clause to: Set rstSuppressList = db.OpenRecordset("Select * From tblReservations Where Year([date_arriv]) =" & intYear1 & " Or year([date_arriv]) =" & intYear2): strStatus = "Q" Adding: OR "[status] = '" & *strStatus & " ' " does not work. THere's an extra space and a quote in the wrong place: * *" OR [status] = '" & *strStatus & "' " -- Marsh- Hide quoted text - - Show quoted text - Readability (and robustness) is very much enhanced by using a simple function: “ OR [Status] = “ & As_text(strStatus) The function As_text just returns strStatus surrounded with single quotes. Imb. |
#12
| |||
| |||
|
|
Thanks, never seen that before. I don't have that function (A2003). |
#13
| |||
| |||
|
|
Thanks, never seen that before. I don't have that function (A2003). Hi Paul, Well, make it! Function As_text (ThisText As String) As String As_text = "'" & ThisText & "'" ' This reads as: " ' " & ThisText & " ' " End Function and place it in a Module. Imb. |
#14
| |||
| |||
|
|
I hate quotes |
#15
| |||
| |||
|
|
On 28/01/2011 08:27:01, imb wrote: Thanks, never seen that before. I don't have that function (A2003). Hi Paul, Well, make it! Function As_text (ThisText As String) As String As_text = "'" & ThisText & "'" ' This reads as: " ' " & ThisText & " ' " End Function and place it in a Module. Imb. Hi Imb For robustness & readability, I think this is better. Function As_text (ThisText As String) As String * *If IsNull(ThisText) = False Then * * * If InStr(ThisText, Chr(34)) > 0 Then * * * * *ThisText = ChangeChars(CStr(ThisText), Chr(34), "'") * * * End If * *End If * *As_text = Chr$(34) & ThisText & Chr$(34) End Function I hate quotes Phil- Hide quoted text - - Show quoted text - |
#16
| |||
| |||
|
|
On Jan 29, 12:22*am, "Phil" <p... (AT) stantonfamily (DOT) co.uk> wrote: On 28/01/2011 08:27:01, imb wrote: Thanks, never seen that before. I don't have that function (A2003). Hi Paul, Well, make it! Function As_text (ThisText As String) As String As_text = "'" & ThisText & "'" ' This reads as: " ' " & ThisText & " ' " End Function and place it in a Module. Imb. Hi Imb For robustness & readability, I think this is better. Function As_text (ThisText As String) As String * *If IsNull(ThisText) = False Then * * * If InStr(ThisText, Chr(34)) > 0 Then * * * * *ThisText = ChangeChars(CStr(ThisText), Chr(34), "'") * * * End If * *End If * *As_text = Chr$(34) & ThisText & Chr$(34) End Function I hate quotes Phil- Hide quoted text - - Show quoted text - Hi Phil, Some comments on your working-out of the As_text function. - Indeed, the function was simplified to ease a quick start. - if ThisText is a String, it has no meaning to test for a Null-value. - In order to conserve single quotes in ThisText, you can better double them (two single quotes) instead of removing them. Imb. |
#17
| |||
| |||
|
|
On 28/01/2011 23:52:13, imb wrote: On Jan 29, 12:22*am, "Phil" <p... (AT) stantonfamily (DOT) co.uk> wrote: On 28/01/2011 08:27:01, imb wrote: Thanks, never seen that before. I don't have that function (A2003). Hi Paul, Well, make it! Function As_text (ThisText As String) As String As_text = "'" & ThisText & "'" ' This reads as: " ' " & ThisText & " ' " End Function and place it in a Module. Imb. Hi Imb For robustness & readability, I think this is better. Function As_text (ThisText As String) As String * *If IsNull(ThisText) = False Then * * * If InStr(ThisText, Chr(34)) > 0 Then * * * * *ThisText = ChangeChars(CStr(ThisText), Chr(34), "'") * * * End If * *End If * *As_text = Chr$(34) & ThisText & Chr$(34) End Function I hate quotes Phil- Hide quoted text - - Show quoted text - Hi Phil, Some comments on your working-out of the As_text function. - Indeed, the function was simplified to ease a quick start. - if ThisText is a String, it has no meaning to test for a Null-value. - In order to conserve single quotes in ThisText, you can better double them (two single quotes) instead of removing them. Imb. Hi Imb Can't remember the exact circumstances, but we had a lady called Mrs O'Hara. The trouble I had with something like SELECT MyTable.* FROM MyTable where SurName = '" & SurName & "';" Winges about 3 single quotes. So any field with a single or double quote can be a pain in the ar.. to sort out. Love the Irish really Phil- Hide quoted text - - Show quoted text - |
![]() |
| Thread Tools | |
| Display Modes | |
| |