Connecting Tech Pros Worldwide Forums | Help | Site Map

open a record,

Member
 
Join Date: Sep 2008
Posts: 71
#1: Dec 23 '08
i have a form bound to a table, with a primary key(autonumber) "recordno"
on this form, i have a dlookup that looks up a specific "recordno".

how can i get this form to open up the record corresponding to the value that the dlookup outputs.

puppydogbuddy's Avatar
Expert
 
Join Date: May 2007
Location: Florida
Posts: 1,915
#2: Dec 23 '08

re: open a record,


in the code below txtrecordno represents the textbox on the form that you are using for the recordno you want to display via the DLookup, although your use of the DLookup to determine what record you want to display does not make sense to me. Replace any illustrative names I used for the objects in your application with their actual names.

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtrecordno_AfterUpdate()
  2. If DCount("[recordno]", "YourTable", "[recordno] = " & Me.txtrecordno) > 0 Then
  3.         DoCmd.OpenForm Me, , , "[recordno] = " & Me.txtrecordno
  4. Else
  5.         MsgBox "The recordno you entered does not exist."
  6.         Me.txtrecordno.SetFocus
  7. End If
  8. End Sub
  9.  
Reply

Tags
dlookup, recordset