Hi,
I have this form which so far displays data if its there or lets you enter new data in the form. I have a combo box which at present inserts whatever is selected into my table.
How can I make it so the id of the item in the combobox is inserted instead of the actual text displayed.
The table where the ComboBox data comes from is like this:
PackageID: An Autonumber
Package: Description of selected package.
How can I also make it, so that when I go back to the form to view the saved data, the combobox is preselected with corresponding id.
Heres my code so far.
Private Sub Form_Activate()
'On Error GoTo errHandler
Dim sSql As String
Dim adoRSA As ADODB.Recordset
Dim adoField As ADODB.Field
Dim lCol As Long
Dim lRow As Long
Dim lWidth As Long
Dim labEntry As Label
Dim txtEntry As TextBox
Dim vArr As Variant
Dim lX As Long
Dim sHide As String
If Me.Tag = "loaded" Then Exit Sub
Me.Tag = "loaded"
Me.Icon = frmAccount.Icon
'txtEdit.Visible = False
'load IP details
sSql = "SELECT IPdetails.* " & _
"FROM IPdetails WHERE Clis = " & glCli
Set adoRS1 = gadoConnDB.Execute(sSql)
If Not adoRS1.EOF Then
'If adoRS1(tickProgrammed.DataField) Then
'tickProgrammed.Value = 1
'Else
'tickProgrammed.Value = 0
'End If
For Each txtEntry In txtIPDetails
txtEntry.Text = adoRS1(txtEntry.DataField)
'If tickProgrammed.Value Then
'txtEntry.BackColor = &H8080FF
'Else
'txtEntry.BackColor = &H80000005
'End If
Next
'framePBX.Tag = .TextMatrix(.Row, 2) 'save lCli
Else
For Each txtEntry In txtIPDetails
txtEntry.Text = ""
txtEntry.BackColor = &H80000005
Next
'tickProgrammed.Value = 0
'framePBX.Tag = .TextMatrix(.Row, 2) 'save lCli
End If
Dim strSQL As String 'Declare the variables we need
'Load the data
'** change this SQL to load the data you want.
strSQL = "SELECT * FROM PackageType"
'** change oConn to the name of your Connection object
Set adoRScombo1 = gadoConnDB.Execute(strSQL)
'Fill the combo box (or ListBox)
'** change the name of the combo to the one you want to fill
With CboPackageType
.Clear
Do While Not adoRScombo1.EOF
'** change the name of the field here to the one you want to show
.AddItem adoRScombo1.Fields("Package").Value
adoRScombo1.MoveNext
Loop
End With
'Tidy up
adoRScombo1.Close
Set adoRScombo1 = Nothing
End Sub
Private Sub cmdUpdateContact_Click()
Dim sSql As String
Dim adoRS1 As New ADODB.Recordset
Dim txtEntry As TextBox
'update ip data
sSql = "SELECT IPdetails.* " & _
"FROM IPdetails WHERE Clis = " & glCli
adoRS1.Open sSql, gadoConnDB, adOpenStatic, adLockOptimistic
If adoRS1.EOF Then
adoRS1.AddNew
End If
adoRS1("Clis") = glCli
adoRS1("dtype") = CboPackageType
'If tickProgrammed.Value = 0 Then
'adoRS1(tickProgrammed.DataField) = False
'Else
'adoRS1(tickProgrammed.DataField) = True
'End If
For Each txtEntry In txtIPDetails
adoRS1(txtEntry.DataField) = Trimmer(txtEntry.Text)
Next
adoRS1.Update
cmdUpdateContact.Enabled = False
End Sub