Get Specific Record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, i am not a programmer but a dabbler and need some help with the
following please.

I get a record from my table by dtAdded with the code below... How would i
change this if i put a combo box to select the record i want, as this takes
the latest record by date but i want to be able to select the record... I
hope i am clear enough ??

strSql = "SELECT * FROM tbl_CIANumberRequest ORDER BY dtAdded DESC"

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSql, , dbReadOnly)

strReqNo = rst!RequestID
strReqC = rst!RequestorCName
strReqS = rst!RequestorSName
 
This is a very common situation. Combo boxes are often used to find a record
in the form's record source and make it the current record. In most cases
(but not always) the combo is an unbound control. For example purposes,
let's say we want to find a person by their employee ID number. The code in
the combo's After Update event would look something like this:

Private Sub cboEmpID_AfterUPdate()
Dim rst As Recordset

Set rst = Me.RecordsetClone
With rst
.FindFirst "[EMP_ID] = " & Me.cboEmpID
If Not .NoMatch Then
Me.BookMark = .BookMark
End If
End With

End Sub
 
Thanks very much Dave, will use your code...
--
Les


Klatuu said:
This is a very common situation. Combo boxes are often used to find a record
in the form's record source and make it the current record. In most cases
(but not always) the combo is an unbound control. For example purposes,
let's say we want to find a person by their employee ID number. The code in
the combo's After Update event would look something like this:

Private Sub cboEmpID_AfterUPdate()
Dim rst As Recordset

Set rst = Me.RecordsetClone
With rst
.FindFirst "[EMP_ID] = " & Me.cboEmpID
If Not .NoMatch Then
Me.BookMark = .BookMark
End If
End With

End Sub
--
Dave Hargis, Microsoft Access MVP


Les said:
Hello, i am not a programmer but a dabbler and need some help with the
following please.

I get a record from my table by dtAdded with the code below... How would i
change this if i put a combo box to select the record i want, as this takes
the latest record by date but i want to be able to select the record... I
hope i am clear enough ??

strSql = "SELECT * FROM tbl_CIANumberRequest ORDER BY dtAdded DESC"

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSql, , dbReadOnly)

strReqNo = rst!RequestID
strReqC = rst!RequestorCName
strReqS = rst!RequestorSName
 
Back
Top