If allready exist

  • Thread starter Thread starter ericsson
  • Start date Start date
E

ericsson

Hi,

I have a table with fields (Order_no, Type, Reason,,,,,).
I want to create a form with this fields, and when I have typed in the
Order_no and press the tab-key, it will chek if the Order_no already exist
(not when I have typed all fields).
-If so, it would automatically open this record.
-If not, I´ll type in text in the other fields in the new record.
How do I fix that!
Thanks
 
Use a recordset or the DLookup() function to find the existing record based
on its Order_no. The recordset is faster:

Function FastLookup(strFieldName As String, _
strTableName As String, _
strWhere As String) As Variant
'Arvin Meyer 4/9/1997

Dim strSQL As String
Dim rst As DAO.Recordset
Dim db As DAO.Database

Set db = CurrentDb

strSQL = "SELECT " & strFieldName & " FROM " & _
strTableName & " WHERE " & strWhere & ";"

Set rst = db.OpenRecordset(strSQL, dbOpenSnapshot)

If rst.RecordCount <> 0 Then
FastLookup = rst(strFieldName)
Else
FastLookup = Null
End If

End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Back
Top