Link to home
Start Free TrialLog in
Avatar of Phereklos
Phereklos

asked on

Open form to current record, but then cann't change record

I have a button that opens a for to the current record, unless there is no record at which point is opens the form in add mode:

If IsNull(Me.BorrowerInquiryID) Then
    DoCmd.OpenForm "frmPasswords", acNormal, , , acFormAdd

Else
    DoCmd.OpenForm "frmPasswords", , , "[BorrowerInquiryID]= " & Me.BorrowerInquiryID & ""

This works fine; however, on frmPasswords I have a combo box that allows the user to chose another "borrower's inquiry."  When I open the form directly from the navigation pane, the combo box works find; when I open the from with the button as programmed above, the combo box does not go to the selected record:

    DoCmd.SearchForRecord , "", acFirst, "[VHDABorrowerInquiryID] = " & Str(Nz(Screen.ActiveControl, 0))

What can I do to my button's code so it does not lock the frmPassword to one record?

Thanks!
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image


If IsNull(Me.BorrowerInquiryID) Then
    DoCmd.OpenForm "frmPasswords", acNormal, , , acFormAdd

Else

'this part of the code is limiting the records in frmPasswords to one

    DoCmd.OpenForm "frmPasswords", , , "[BorrowerInquiryID]= " & Me.BorrowerInquiryID & ""

end if


use this codes instead

If IsNull(Me.BorrowerInquiryID) Then
    DoCmd.OpenForm "frmPasswords", acNormal, , , acFormAdd

Else

'this part of the code is limiting the records in frmPasswords to one

    DoCmd.OpenForm "frmPasswords", Openargs:= Me.BorrowerInquiryID
end if

' NOW in the load event of frmPasswords place this codes

private sub form_load()

if len(me.openargs)>0 then
  with me.recordsetclone
      .findfirst "[BorrowerInquiryID]= " & Me.Openargs

      if not .nomatch then
           me.bookmark=.bookmark
           else
             msgbox "Record not found"
      end if
  end with

end if

end sub
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Phereklos
Phereklos

ASKER

Thank you.  I will read up on openargs - haven't used that yet.  Appreciate your help.