Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old April 24th, 2008, 12:58 AM
andy.v andy.v is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 5 andy.v User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 26 m 16 sec
Reputation Power: 0
How to fill a form with a recordset with a "complicated" where clause ?

dear colleagues !

i fill a form with a recordset using this simple code:

Private Sub Form_Open(Cancel As Integer)

Dim rs As ADODB.Recordset

Set rs = New ADODB.Recordset

rs.ActiveConnection = CurrentProject.AccessConnection
rs.Source = "select logon_name, name_last_lat, name_first_lat, id from tbl_user where (id > 100)"
rs.LockType = adLockOptimistic
rs.CursorType = adOpenKeyset
rs.Open

Set Me.Recordset = rs
Set rs = Nothing

End Sub

how could i build a more sophisticated "where" clause than "id > 100" ?

i would be interested in using of something like charindex tsql function.

thank you in advance !

Reply With Quote
  #2  
Old May 7th, 2008, 04:28 PM
Phoenix_riser Phoenix_riser is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 223 Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 2 h 7 m 21 sec
Reputation Power: 14
How do you mean? Such as:

strSQL1 = "select * from TABLE where X = 1 AND Y = 2 or Z =3"
If it is very long put:

Dim vString

vString = "select * from TABLE where"
vString = vString & "X = 1 AND Y = 2 or Z =3"
strSQL1 = vString

Quote:
Originally Posted by andy.v
dear colleagues !

i fill a form with a recordset using this simple code:

Private Sub Form_Open(Cancel As Integer)

Dim rs As ADODB.Recordset

Set rs = New ADODB.Recordset

rs.ActiveConnection = CurrentProject.AccessConnection
rs.Source = "select logon_name, name_last_lat, name_first_lat, id from tbl_user where (id > 100)"
rs.LockType = adLockOptimistic
rs.CursorType = adOpenKeyset
rs.Open

Set Me.Recordset = rs
Set rs = Nothing

End Sub

how could i build a more sophisticated "where" clause than "id > 100" ?

i would be interested in using of something like charindex tsql function.

thank you in advance !

Reply With Quote
  #3  
Old May 8th, 2008, 01:10 AM
andy.v andy.v is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 5 andy.v User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 26 m 16 sec
Reputation Power: 0
Quote:
Originally Posted by Phoenix_riser
How do you mean? Such as:

strSQL1 = "select * from TABLE where X = 1 AND Y = 2 or Z =3"
If it is very long put:

Dim vString

vString = "select * from TABLE where"
vString = vString & "X = 1 AND Y = 2 or Z =3"
strSQL1 = vString


hello, phoenix riser !

thank you for your assistance !

i mean that i want to have the following where clause:

select ... from ... where ((int_field_1 is 100) and (char_field_2 contains "abcd") and (date_field_3 belongs to may-2008) etc.)

any idea ?

Reply With Quote
  #4  
Old May 8th, 2008, 08:34 AM
Phoenix_riser Phoenix_riser is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 223 Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 2 h 7 m 21 sec
Reputation Power: 14
Good day,

Firstly this first part is ripped from a project you have and I’ve not checked that is works outside of it.

I do my open database etc… slightly differently so I would do…


First thing is that actual dates are a pain in VB but if you literally have the words May-2008 then this is different.

Set db1 = DBEngine.OpenDatabase(frmMain..DB.Text) ‘I keep my databases in text files locally at this stage as we are moving servers but hardcode yours in here

Code:
strSQL1= "Select select logon_name, name_last_lat, name_first_lat, id From tbl_user WHERE int_field_1  = ‘100’ AND char_field_2 = “abcd” AND date_field_3 = “may-2008”
'
Set rs1 = db1.OpenRecordset(strSQL1)
                                  
                                    If rs1.RecordCount > 0 Then
                                        rs1.MoveLast
                                        lngRecordcount1 = rs1.RecordCount
                                        rs1.MoveFirst
                                    Else
                                        lngRecordcount1 = 0
                                    End If

For Counter1 = 1 To lngRecordcount1



Etc….

For a date you might be best splitting it down as I have problems with dates, to do this I do the following. In your case change the below from less than to equals to. I wonder if this code might be useful in general?

Code:
vDate1 = rs1.Fields("date_field_3 ") 
            vDate = Len(rs1.Fields("order_created"))
            vYear = Mid(vDate1, 7, 4) 'year
            vMonth = Mid(vDate1, 4, 2) 'month
            vDate = Mid(vDate1, 1, 2) 'date
            
            
                        If vYear > vSYear Then 'if the date year selected is less that above ignore
                            vOkay = "1"
                        Else
                            If vYear = vSYear Then  'if year is same need to check mont
                                If vMonth > vSMonth Then 'if month is more than then it is okay
                                        vOkay = "1"
                                Else
                                    If vMonth = vSMonth Then
                                            If vDate >= vSDate Then
                                                vOkay = "1"
                                            Else
                                                'day in the month is less so ignore
                                            End If
                                    End If
                                End If
                            Else
                            End If
                        End If
                        'if the day is after or the same as the one selected then check it's the same as or before the end day
                               
                        If vOkay = "1" Then
                        
                            If vYear < vFYear Then 'if the date year selected is less that above ignore
                                vOkay = "2"
                            Else
                                If vYear = vFYear Then  'if year is same need to check month
                                    If vMonth < vFMonth Then 'if month is more than then it is okay
                                            vOkay = "2"
                                    Else
                                        If vMonth = vFMonth Then
                                                If vDate <= vFDate Then
                                                    vOkay = "2"
                                                Else
                                                    'day in the month is more so ignore
                                                End If
                                        End If
                                    End If
                                Else
                                End If
                            End If
                        Else
                        End If

Reply With Quote
  #5  
Old May 10th, 2008, 08:11 AM
andy.v andy.v is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 5 andy.v User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 26 m 16 sec
Reputation Power: 0
hello phoenix !

thanks for your time !

i think i explained not clearly what i want.

i would like to to have criteria applied to fields of diffrent types in "where" clause:
-- i want an int field to be greater than 100
-- i want a date field to be earlier that 1/1/1999
-- i want a character field to contain a specific substring etc.

av

Reply With Quote
  #6  
Old May 10th, 2008, 02:07 PM
Phoenix_riser Phoenix_riser is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 223 Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 2 h 7 m 21 sec
Reputation Power: 14
For the 100 you need

> 100 (I get my < and > wrong way round sometimes!)
so fieldX => '100'

For dates, split them like I do to be sure on the loop around. Either that or you could have trouble with the dates. It's more programming but write it once as a module and it will be fine.

for a substring such as vWhatever you need to put

field = "& vWhatever &" or whatever you need it to be such as greater than or less than (it might be '"& - I'm away from a PC with any programs on at the moment!!)

Am I on the right wave lenght now?


Quote:
Originally Posted by andy.v
hello phoenix !

thanks for your time !

i think i explained not clearly what i want.

i would like to to have criteria applied to fields of diffrent types in "where" clause:
-- i want an int field to be greater than 100
-- i want a date field to be earlier that 1/1/1999
-- i want a character field to contain a specific substring etc.

av

Reply With Quote
  #7  
Old May 11th, 2008, 03:11 AM
andy.v andy.v is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 5 andy.v User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 26 m 16 sec
Reputation Power: 0
hello, phoenix riser !

thank you very much ! you are tuned now.

i am interested in string operations mostly. say i am looking for all the cities whose names contain "LL" and it is not "lloret de mar" only (starting with "LL") but "versailles" also (containing "LL" at some - generally speaking unknown - position). i guess i can fill a form with such a list using vba code. my question is whether i can fill that form with the list using "where" clause only:

rs.source = "select city_code, city_name from tbl_city where (city_name contains "ll")".

thank you in advance !

av

Reply With Quote
  #8  
Old May 12th, 2008, 03:47 AM
Phoenix_riser Phoenix_riser is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 223 Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 2 h 7 m 21 sec
Reputation Power: 14
Try...

Code:
strSQL = "SELECT * FROM TABLE WHERE Member_code LIKE '*" & vVariable & "*' "


Take away the * from before or after if you only want to search start/end of string.

Quote:
Originally Posted by andy.v
hello, phoenix riser !

thank you very much ! you are tuned now.

i am interested in string operations mostly. say i am looking for all the cities whose names contain "LL" and it is not "lloret de mar" only (starting with "LL") but "versailles" also (containing "LL" at some - generally speaking unknown - position). i guess i can fill a form with such a list using vba code. my question is whether i can fill that form with the list using "where" clause only:

rs.source = "select city_code, city_name from tbl_city where (city_name contains "ll")".

thank you in advance !

av

Last edited by Phoenix_riser : May 12th, 2008 at 04:22 AM.

Reply With Quote
  #9  
Old May 14th, 2008, 08:27 AM
andy.v andy.v is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 5 andy.v User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 26 m 16 sec
Reputation Power: 0
hello, phoenix riser !

it works ! the only thing - it should be % and not * ...

thank you !

av

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > How to fill a form with a recordset with a "complicated" where clause ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway