Here's how I'd do it: make a recordset that looks for a matching record. If there is a record, grab the ID from the recordset and open the second form filtered to just that record. If there are no records, open the form in add mode, populating the two fields on the second form from the variables used in the recordset.
Like this:
Private Sub Command6_Click()
On Error GoTo Error
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSql As String
Dim strWhere As String
Dim strCustomer As String
Dim strLease As String
Set db = CurrentDb
strCustomer = Me!txtCustomer
strLease = Me!txtLease
strWhere = " WHERE Customer = '" & strCustomer & "' AND " _
& " Lease = '" & strLease & "'"
strSql = "SELECT WhateverID, Customer, Lease " _
& " FROM tblWhatever " & strWhere
Set rst = db.OpenRecordset(strSql, dbOpenSnapshot)
If (rst.BOF And rst.EOF) Then
Call DoCmd.OpenForm("frmWhatever", , , , acFormAdd)
Forms!frmWhatever!txtCustomer = strCustomer
Forms!frmWhatever!txtLease = strLease
Else
Call DoCmd.OpenForm(frmWhatever, , , strWhere, acFormEdit)
End If
rst.Close
Set rst = Nothing
db.Close
Set db = Nothing
Exit Sub
Error:
Call MsgBox(err.Number & ": " & err.Description)
End Sub
You will, of course, have to adjust names of objects here, but this should be a decent starting point. I've not tested it, so there may be a problem or two. Just get back to this thread if you have any trouble.
Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995
Take a look at the Developers' section of the site for some helpful fundamentals.