Results 1 to 5 of 5
  1. #1
    Join Date
    May 2008
    Posts
    9

    Exclamation Unanswered: How to populate the datagrid in VB6

    Hello,

    I am using an SQL database and VB6, I however have hit a snag on developing my application because I have failed to use a datagrid contol.

    I would like under the click event of a command button to be able to select particular fields from a database tha match a given criteria such that the results are fed into the data grid and the report therefore be based on the populated datagrid.

    This means that the query will be selecting from the database records that are between values in textbox1 and textbox2 or rather datetimepicker1 and datetimepicker2 in some instances.

    My problem is basically populating the datagrid after selecting anyone who has that code please help

  2. #2
    Join Date
    Feb 2009
    Posts
    23
    first declare this on your module

    Public db_rDel As ADODB.Connection
    Function load_rDel()
    Set db_rDel = New Connection
    db_rDel.Open "PROVIDER=MSDataShape;Data PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\database.mdb"
    End Function

    on your button click on form

    Private Sub Command1_Click()
    On Error GoTo ERR123

    Call load_sDel
    Set rs_sDel = New Recordset
    rs_sDel.Open "SELECT * FROM table " & _
    " Where record1 like '" & text1.Text & "%' and record2 like '" & text2.Text & "%'", db_sDel, adOpenStatic, adLockOptimistic

    exit sub
    err123:
    msgbox err.description
    end sub

  3. #3
    Join Date
    Feb 2009
    Posts
    11
    How would this translate to using VB Express 2008 and a Microsoft Access Database?

  4. #4
    Join Date
    Feb 2009
    Posts
    29
    'i think there are logical errors on your query. you already put AND in all fields which means you the user MUST input an information for that fields.

    'if the user inputs only abc on ADDRESS_REF the computer will search this info....
    'ADDRESS_REF like abc
    'HOUSE_NUMBER LIKE ""
    'STREET_NAME LIKE ""
    'TOWN_NAME LIKE ""
    'the computer will return a record or row that matches all that field.

    'RECOMMENDATION:
    'Try to use IF.... elseif.....else... statement to avoid logical error
    'example, code this on your vb. NOTE: this is not a query
    'dont know the control name thats why i put the name of your fields
    'if the user inputs only on ADDRESS_REF textbox then the query must search only for ADDRESS_REF field
    'if ADDRESS_REF.text <> "" and HOUSE_NUMBER.text = "" and STREET_NAME.text = "" and TOWN_NAME.text ="" then
    'select * from yourtable WHERE ADDRESS_REF like '%" & ADDRESS_REF.text & "%'"
    'ADDRESS_REF textbox have a value already then the user knows the house number and input it on the
    'HOUSE_NUMBER textbox then the query must search for both textbox
    'elseif ADDRESS_REF.text <> "" and HOUSE_NUMBER.text = "" and STREET_NAME.text = "" and TOWN_NAME.text =""
    'select * from yourtable WHERE ADDRESS_REF like '%" & ADDRESS_REF.text & "%' and HOUSE_NUMBER like '%" & HOUSE_NUMBER.text & "%'

    'continue this statement until all your textbox is not equal to null (<> "")
    'then put it on textchange of your textboxes
    'Private Sub ADDRESS_REF_Change()
    'Private Sub HOUSE_NUMBER_Change()
    'Private Sub STREET_NAME_Change()
    'Private Sub TOWN_NAME_Change()


    'also i use vb 6.0, now i am trying to find the version u use

  5. #5
    Join Date
    Feb 2009
    Posts
    29
    'for OR/AND statement
    'records on your database
    'ADDRESS_REF HOUSE_NUMBER STREET_NAME TOWN_NAME
    ' ABCD 123 MALAYO DIMAKITA
    ' BCDE 563 DULONA PHIL

    'user input
    'ADDRESS_REF = BC
    'HOUSE_NUMBER = 2

    'if you use AND the returning records is
    'ADDRESS_REF HOUSE_NUMBER STREET_NAME TOWN_NAME
    ' ABCD 123 MALAYO DIMAKITA

    'if you use OR the returning records is
    'ADDRESS_REF HOUSE_NUMBER STREET_NAME TOWN_NAME
    ' ABCD 123 MALAYO DIMAKITA
    ' BCDE 563 DULONA PHIL

    'hope you got what i am trying to explain to you.
    'me i have oracle book and subject when i was i school.
    'on that book it explain the DIFFERENCE of OR and AND statement.
    'i have applications that have the codes for the "searching" you wanna happen but
    'it's in VB 6.0 format, not sure if compatible with 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •