setting fields on form from previous form

marnieg

Registered User.
Local time
Yesterday, 19:35
Joined
Jul 21, 2009
Messages
70
I have a form with two fields, street number and street name. If the combination of the two does not exist on a current record I want to open the form with these values already set on the form. Here is the code I have, but get error on highlighted row. The Contacts form is used for adding and editing of records.


Code:
strnum = Me![strnum]
strname = Me![strname]
intcount = DCount("ID", "[Contacts]", "Address = '" & strname & "' and street_no = '" & strnum & "'")
    Dim stdocname As String
      stdocname = "Contacts"
If intcount > 0 Then
      Dim strLinkCriteria  As String
      strLinkCriteria = "[Address] =" & "'" & Me![strname] & "'" & " And [street_no]=" & "'" & Me![strnum] & "'"
       DoCmd.Close
      DoCmd.OpenForm stdocname, , , strLinkCriteria
Else
      
  [B][COLOR="Red"]    Me.strname = Forms![Contacts]![Address][/COLOR][/B]
      Me.strnum = Forms![Contacts]![street_no]
      DoCmd.Close
      DoCmd.OpenForm stdocname
      DoCmd.GoToRecord , , acNewRec
   End If

Please advise the best method of doing this.
 
I am confused by what you are trying to do. Forms don't store data. Tables store data. If your dLookup() didn't find a matching record, why do you think you can find the record by referencing a form?

If you open a form using criteria, the form will open to the requested record if it is found. If the record is not found, it will open to a new record.

If you want the popup form to pick up already typed values from the calling form, do it in the popup Form's BeforeInsert event.
Me.strname = Forms!callingform!Address
Me.strnum = Forms!callingform!street_no
 

Users who are viewing this thread

Back
Top Bottom