Combined Query of Data room Charging System

Source: Internet
Author: User

 
Private Sub cmdInquire_Click()
FgStuinfo. clear' Clear the list before each query to avoid repeated Dim mrc As ADODB. recordset Dim txtSQL As String Dim msgText As String Dim dok1 As Boolean Dim dok2 As Boolean Dim dok3 As Boolean Dim Title (0 To 6) As string' if the condition content changes, you only need to change the specific content here.
'Note that the name here is the name of the column to be queried in the SQL table. Title (0) = "cardno" Title (1) = "name" Title (2) = "ondate" Title (3) = "ontime" Title (4) = "offdate" Title (5) = "offtime" Title (6) = "consumemoney" Dim compose (0 To 1) As String compose (0) = "and" compose (1) = "or" On Error Resume Next txtSQL = "select * from loginrecord_info where" 'the first row of condition satisfies If Trim (comboFeild (0 ). text) <> "" And combosign (0 ). text <> "" And txtContent (0 ). te Xt <> "" Then dok1 = True Else dok1 = False End If 'the second row meets the condition of If comboFeild (1 ). text <> "" And combosign (1 ). text <> "" And txtContent (1 ). text <> "" Then dok2 = True Else dok2 = False End If 'the third row meets the condition of If comboFeild (2 ). text <> "" And combosign (2 ). text <> "" And txtContent (2 ). text <> "" Then dok3 = True Else dok3 = False End If 'a row of conditions does not have If (dok1 = False And dok2 = False And dok3 = False) Then If comboFei Ld (0). Text = "" Then MsgBox "enter the field name! "Exit Sub Else If combosign (0). Text =" "Then MsgBox" Please input the operator! "Exit Sub Else If txtContent (0). Text =" "Then MsgBox" Enter the content to query! "Exit Sub End If 'has the first line of condition If dok1 = True Then txtSQL = txtSQL & Title (comboFeild (0 ). listIndex) & Trim (combosign (0 ). text) & _ "'" & Trim (txtContent (0 ). text) & "'" End If' has the condition of the second line If dok2 = True Then If dok1 = True Then If ComboOperater (0 ). text = "" Then MsgBox "select a composite relationship! "Exit Sub Else txtSQL = txtSQL & compose (ComboOperater (0 ). listIndex) & Title (comboFeild (1 ). listIndex) & Trim (combosign (1 ). text) & _ "'" & Trim (txtContent (1 ). text) & "'" End If Else txtSQL = txtSQL & Title (comboFeild (1 ). listIndex) & Trim (combosign (1 ). text) & _ "'" & Trim (txtContent (1 ). text) & "'" End If' has the third row condition If dok3 = True Then If dok2 = True Then If dok1 = True Then If ComboOperater (1 ). T Ext = "" Then MsgBox "select the second composite link! "Exit Sub Else txtSQL = txtSQL & compose (ComboOperater (1 ). listIndex) & Title (comboFeild (2 ). listIndex) & _ combosign (2 ). text & "'" & Trim (txtContent (2 ). text) & "'" End If Else' If dok1 = false txtSQL = txtSQL & compose (ComboOperater (1 ). listIndex) & Title (comboFeild (2 ). listIndex) & _ combosign (2 ). text & "'" & Trim (txtContent (2 ). text) & "'" End If Else If dok1 = True Then If ComboOperater (0 ). text = "" T Hen MsgBox "Enter the first composite relationship! "Exit Sub Else 'dok2 = true, dok3 = true, dok1 = false txtSQL = txtSQL & compose (ComboOperater (0 ). listIndex) & Title (comboFeild (2 ). text) & _ combosign (2 ). text & "'" & Trim (txtContent (2 ). text) & "'" End If Else txtSQL = txtSQL & Title (comboFeild (2 ). listIndex) & combosign (2 ). text & _ "'" & Trim (txtContent (2 ). text) & "'" End If Set mrc = ExecuteSQL (txtSQL, msgText) With fgStuinfo. rows = 2. cel LAlignment = 4. textMatrix (1, 0) = "card number ". textMatrix (1, 1) = "name ". textMatrix (1, 2) = "logon date ". textMatrix (1, 3) = "Logon Time ". textMatrix (1, 4) = "downtime date ". textMatrix (1, 5) = "downtime ". textMatrix (1, 6) = "Consumption amount" Do While Not mrc. EOF. rows =. rows + 1. cellAlignment = 4. textMatrix (. rows-1, 0) = Trim (mrc. fields (0 )). textMatrix (. rows-1, 1) = Trim (mrc. fields (2 )). textMatrix (. rows-1, 2) = Trim (mrc. fields (5) ). TextMatrix (. rows-1, 3) = Trim (mrc. fields (6 )). textMatrix (. rows-1, 4) = Trim (mrc. fields (7 )). textMatrix (. rows-1, 5) = Trim (mrc. fields (8 )). textMatrix (. rows-1, 6) = Trim (mrc. fields (10) mrc. moveNext Loop If. textMatrix (2, 0) = "" then'. If no result exists, prompt! MsgBox "does not match the result you want" Exit Sub End If End WithEnd Sub
Here, we also need to pay attention to the meaning of the listindex attribute! Its return value is a number, corresponding to the array expression we previously declared!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.