Re: reg SQL query
- From: argusy <argusy@xxxxxxxxxxxxxxx>
- Date: Tue, 17 Mar 2009 20:37:05 +1030
argusy wrote:
Ramkumar wrote:
> Ya i tried with the Mike's coding.
> But it's giving error " SUB OR FUNCTION NOT DEFINED " and it shows error near to monthName().
> I tried with that coding before posting this problem.
> that's why i posted this problem again.
> I AM USING VISUAL BASIC 5.0 TO MY PROJECT.
> IT WON'T SUPPORT MonthName() function.
> can u give some idea reg my problem.
>
>
> Thanks and Regards,
>
> Ram
>
>
Sorry, my post wasn't that clear, when I read it back to myself
What I was really trying to do, was to get you to take a look at Mike's reasoning (and code) to use IN THE QUERY, and also his tips for error trapping.
as for monthname(), sure it's VB6, so what's wrong with going back to your VB5 code to populate combo1?
Graham
>> Ramkumar wrote:
>>> Hi
>>>
>>> During the FORM LOAD i'm loading the months and the current year in the combobox and text box respectively. The coding for month and year is given below.
>>>
>>> For MONTH:
>>>
>>> Dim i As Integer
>>> For i = 1 To 12
>>> combo1.AddItem Format(DateSerial(Year(Date), i, 1), "MMMM")
>>> Next
>>>
>>> For YEAR:
>>>
>>> Dim i As Integer
>>> Dim currentYear As Integer
>>> currentYear = Year(Now)
>>> txtYear.Text = currentYear
>>>
>>> I need to connect the both to an SQL query.
>>>
>>> I connected the YEAR to SQL query as
>>>
>>> curYear = txtYear.text
>>>
>>> But i don't know to connect the month with the SQL query.
>>>
>>> The SQL query is given below
>>>
>>> SELECT CONVERT(CHAR(25),TravelDate,103) as [Journey Date],EID
>>> ,Surname,Forename,' ' + RTRIM(FromAd) AS [From Adr], FromPostCode, ' '+
>>> RTRIM(ToAd) AS [To Adr],ToPostCode FROM Journey
>>> WHERE (MONTH(Journey.TravelDate) = " ? ")
>>> AND (YEAR(Journey.TravelDate) = " & curYear & ")
>>> AND (MileageInward IS Null OR MileageInward=0 OR
>>> (ReturnJny=1 AND (MileageOutward IS Null OR MileageOutward=0)))
>>> ORDER BY TravelDate, CallSignIn, AppTime, FromPostCode
>>>
>>> I AM USING VISUAL BASIC 5.0. SO ANYONE CAN HELP TO GET RID OF THIS PROBLEM....
>>> Reply ASAP.
>>> Thanks in advance.
>>>
>>> Regards,
>>>
>>> Ram
>>
>> Try reading MikeD's response to your previous post - again
>>
>> Even if the combobox is different between VB5 and VB6, (and I'm pretty sure they're the same) at least try his code before posting another request for assistance.
>>
>> At the least, you should see where you _should_ be going with your query
>>
>> Argusy
So you're saying the following doesn't work?
' the next is in formLoad
Dim i As Integer
For i = 1 To 12
combo1.AddItem Format(DateSerial(Year(Date), i, 1), "MMMM")
Next
' some code here, I guess
Dim curYear As Integer ' taking out one variable here
txtYear.Text = Year(now)
curYear = Year(now)
'End of formLoad
' following code is in another sub-routine
SELECT CONVERT(CHAR(25),TravelDate,103) as [Journey Date],EID
,Surname,Forename,' ' + RTRIM(FromAd) AS [From Adr], FromPostCode, ' '+
RTRIM(ToAd) AS [To Adr],ToPostCode FROM Journey
WHERE (MONTH(Journey.TravelDate) = " & Combo1.ItemData(Combo1.ListIndex) & ")"
AND (YEAR(Journey.TravelDate) = " & curYear & ")
AND (MileageInward IS Null OR MileageInward=0 OR
(ReturnJny=1 AND (MileageOutward IS Null OR MileageOutward=0)))
ORDER BY TravelDate, CallSignIn, AppTime, FromPostCode
Note the WHERE statement. As Mike pointed out, you could set a variable in one of the combo1's events eg
curMonth = Combo1.ItemData(Combo1.ListIndex) & ")"
' curMonth defined as a global or form variable, so it can be used in the query
and in the SQL query
.......
WHERE (MONTH(Journey.TravelDate) = " & curMonth & ")"
.......
BTW there's no mention of MonthName(), so I don't see your argument that it's affecting your code
Graham
.
- Follow-Ups:
- Re: reg SQL query
- From: Ramkumar
- Re: reg SQL query
- References:
- reg SQL query
- From: Ramkumar
- Re: reg SQL query
- From: argusy
- Re: reg SQL query
- From: argusy
- reg SQL query
- Prev by Date: Re: reg SQL query
- Next by Date: Re: reg SQL query
- Previous by thread: Re: reg SQL query
- Next by thread: Re: reg SQL query
- Index(es):
Relevant Pages
|