Data bound Combos or Not Data Bound Combos 
Author Message
 Data bound Combos or Not Data Bound Combos

Hi there

I have a data form with not Data Controls and I now want to add a Combo to
the form.  Can I add a Data bound combo to the form, which instead of
directly interfacing with the parent table passed any  changes to a text
string.  I would rather handle the table changes myself than let any data
controllers.

Thanks

Flanagan



Sat, 11 Mar 2000 03:00:00 GMT  
 Data bound Combos or Not Data Bound Combos

Hi,

I would use a standard combo box (not dbCombo). I'm not sure exactly what
you want to obtain but the following code will populate a combobox and an
array of key fields. when the combobox is clicked a parameter querydef is
run which selects a record and populates an array of textboxes (unbound).
You will need some code to write updates back - this is for VB4/5 and
Access - slight changes for VB3:

Sub sFillName() 'usually called in the form load

    Screen.MousePointer = vbHourglass   'may be lengthy
    cboName.Clear       'make sure the combobox is cleared
        Dim dbName As Database
        Dim qdName As QueryDef
        Dim rsName As Recordset
        Dim X%
         Dim sName As String

        Set dbName = OpenDatabase(DB)                   'DB is a string holding the
database path
        Set qdName = dbName.QueryDefs![qryComboFill]    'qryComboFill is a
query held in an Access Db

        With qdName
            Set rsName = .OpenRecordset(dbOpenSnapshot)
        End With

    If rsName.RecordCount < 1 Then
        Screen.MousePointer = vbArrow
        Exit Sub
    rsName.MoveLast
    rsName.MoveFirst
    ReDim sNameIDA(rsName.RecordCount)  'An array previously dim'ed to hold
the key fields (strings) from the table

    For X% = 0 To rsName.RecordCount - 1                        '0 based ListIndex!!
        sName = Trim(rsName("Surname") & ", " & _
            rsName("FirstName") & " " & rsName("MiddleName"))

        cboName.AddItem sName   'names will appear in the combobox
        sPlayerIDA(X%) = rsName("PlayerID")   'load the array with the key

        rsName.MoveNext
    Next

        Set rsName = Nothing
        Set dbName = Nothing
        Set qdName = Nothing
        Screen.MousePointer = vbArrow   'finished
End Sub

You now have a combobox filled with names and an array of key fields. To
fill the form with data when a name is picked from the combobox, place this
in the Click event of the combobox.

Private Sub cboName_Click()

    If cboName.ListIndex = -1 Then Exit Sub     'don't go any further if no
selection made

    Screen.MousePointer = vbHourglass           'busy

    SB1.Panels("Status").Text = "Working...."
    SB1.Refresh
    sNameID = sNameIDA(cboName.ListIndex)               'sNameID is Global

    sPopulate                   'see below
    Screen.MousePointer = vbArrow
    SB1.Panels("Status").Text = "View Mode"
End Sub

Sub sPopulate()

    Dim dbFill As Database
    Dim qdFill As QueryDef
    Dim rsFill As Recordset
    Dim X%

    Set dbFill = OpenDatabase(DB)
    Set qdFill = dbFill.QueryDefs![qryFillForm]

    qdFill.Parameters!Player = sNameID          'sNameID now contains the required
key field

    With qdFill
            Set rsFill = .OpenRecordset(dbOpenSnapshot)
    End With
    rsFill.MoveLast
    rsFill.MoveFirst

    For X% = 0 To rsFill.fields.Count - 1       'assuming that the query returns
the exact number of fields

        If Not IsNull(rsFill.Fields(X%)) Then
            txtFill(X%) = rsFill.Fields(X%)     'txtFill() is an array of text
boxes - easy to fill and
        Else                                            'created at runtime
            txtFill(X%) = ""
        End If
    Next

    sName = rsFill("Surname") & ", " & rsFill("FirstName") & " " &
rsFill("MiddleName")
    frmMain.caption = "Record for : " & sName
    SB1.Panels("PlayerID") = rsFill("PlayerID")
    Set rsFill = Nothing
    Set dbFill = Nothing
    Set qdFill = Nothing

End Sub

Whilst this is a lot more work that using a dbCombo it gives more control.
Also you use much less resources, especially if you create the textboxes
dynamically.

rgds

--
Rob Agnew
TeamSoft Pty Ltd

http://www.teamsoft.com.au



Quote:
> Hi there

> I have a data form with not Data Controls and I now want to add a Combo
to
> the form.  Can I add a Data bound combo to the form, which instead of
> directly interfacing with the parent table passed any  changes to a text
> string.  I would rather handle the table changes myself than let any data
> controllers.

> Thanks

> Flanagan



Sun, 12 Mar 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Data Bound Combo Box within a Data Bound Grid

2. Data-bound Masked Edit makes all data-bound controls not display data

3. Combo Box like Data Bound Combo Box?

4. Problems refreshing data from Data bound Combo Box

5. Data Bound Combo with Textboxes

6. Null values in a bound data combo box

7. Binding combo boxes to a data control

8. Null Values in Data Bound Combo Boxes

9. How to bound data with combo box?

10. data bound combo box

11. VB Question - Data Bound Combo & Directory Path

12. VB 4 to 5 upgrade issue - data bound combo boxes

 

 
Powered by phpBB® Forum Software