Results 1 to 5 of 5

Thread: Simple Problem! Hopfully a simple soultion!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    68

    Cool

    Hi

    Sorry to bother you all!

    I need to write a sql statement to pull records from a database.

    I have made the connection with the Data enviroment and populated a datacombo box with the data.

    I want to be able to click on a data entry and pull up the fields.

    Displaying them in text boxes!

    How can this be done?

    I know that this is so simple that it is an insult to ask you guys but once I can do this simple thing I am sure that I Can move on to greater things.

    Thanks for your help

    Simon

  2. #2
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284
    When the user selects which record that they wish to see you need to run a SQL statement that selects * from you table where a value = the value that the user has selected this would be most effective if it was a primary key field that they selected. When you pull back the record you can just set each text box to the value of each field. If you have your text boxes set up in an array a handy way to do this would be

    for i = 0 to rs.fields.count
    txtBox(i) = rs(i)
    next

    HTH

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    68

    Lightbulb I see!

    Being as dumb as I am how exactually do I pass that SQL statement

    Something like

    open database
    query database
    close database

    What is the VB code?

    And if the controls are bound to the datafields then chaning one will not nessecarly change the others is that right?

    Simon

  4. #4
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284
    If it is ADO you are using you will need a command object and a connection

    Dim cmd As ADODB.Command

    Set cmd = New ADODB.Command
    cmd.ActiveConnection = 'Your connection object here
    cmd.CommandTimeout = 0
    cmd.CommandText = 'your sql string here
    cmd.Execute
    Set cmd = Nothing

  5. #5
    Lively Member
    Join Date
    May 2000
    Posts
    70

    Cool


    From what you said in you first message Simon, it sounds like you already have a DataEnvironment Connection open.

    This is the code I use in that case.

    Dim strSQL As String
    Dim rstTemp As ADODB.Recordset
    Dim fld As ADODB.Field
    i=0

    strSQL = "SELECT Field" _
    & " FROM Table"_
    & " WHERE Table.Field = '" DataComboBox.Text "';"
    ' Identifies which ADO connection is being used for SQL.
    Set rstTemp = DataEnvironment1.Connection1.Execute(strSQL, , adCmdText)

    For Each fld In rstTemp.Fields
    txtBox(i+1) = fld.Value
    Next

    rstTemp.Close
    Set rstTemp = Nothing

    Hope that helps you...If you haven't got you connection open then you will need DataEnvironment1.Connection1.Open
    sort of thing

    Cheers

    Jonny

Posting Permissions

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



Click Here to Expand Forum to Full Width