Information générale
Catégorie:
Bases de données DAO/RDO/ODBC/ADO
I am using the following code to display an access database, 1 record at a time. I would like to make it so the user can pick from a drop down list, instead of having to scroll through the entire database. I though a DataCombo control for the "COMPANY" field would work, but I cant get it to change all the other info to the selection.
Private Sub Form_Load()
Me.Left = GetSetting(App.Title, "Settings", "MainLeft", 1000)
Me.Top = GetSetting(App.Title, "Settings", "MainTop", 1000)
Me.Width = GetSetting(App.Title, "Settings", "MainWidth", 8250)
Me.Height = GetSetting(App.Title, "Settings", "MainHeight", 8000)
Dim db As Connection
Set db = New Connection
dbLocation = GetSetting(App.Title, "Settings", "DBlocation")
If dbLocation = "" Then
Dim sFile As String
With dlgCommonDialog
.DialogTitle = "Open"
.CancelError = False
.Filter = "MDB Files (*.mdb)|*.MDB"
.ShowOpen
If Len(.FileName) = 0 Then
Exit Sub
End If
sFile = .FileName
End With
SaveSetting App.Title, "Settings", "DBlocation", sFile
End If
db.CursorLocation = adUseClient
db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbLocation + ";"
Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open "select * from Data Order by COMPANY", db, adOpenStatic, adLockOptimistic
Dim oText As TextBox
'Bind the text boxes to the data provider
For Each oText In Me.txtFields
Set oText.DataSource = adoPrimaryRS
Next
mbDataChanged = False
End Sub
Private Sub cmdNext_Click()
On Error GoTo GoNextError
If Not adoPrimaryRS.EOF Then adoPrimaryRS.MoveNext
If adoPrimaryRS.EOF And adoPrimaryRS.RecordCount > 0 Then
Beep
'moved off the end so go back
adoPrimaryRS.MoveLast
End If
'show the current record
mbDataChanged = False
Exit Sub
GoNextError:
MsgBox Err.Description
End Sub
Private Sub cmdPrevious_Click()
On Error GoTo GoPrevError
If Not adoPrimaryRS.BOF Then adoPrimaryRS.MovePrevious
If adoPrimaryRS.BOF And adoPrimaryRS.RecordCount > 0 Then
Beep
'moved off the end so go back
adoPrimaryRS.MoveFirst
End If
'show the current record
mbDataChanged = False
Exit Sub
GoPrevError:
MsgBox Err.Description
End Sub
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement