Solved Open form to spesific record or add it (1 Viewer)

npa3000

Member
Local time
Tomorrow, 01:12
Joined
Apr 16, 2021
Messages
36
Well, I have my order form and a button which it should open us the invoice form for this spesific order, if exists or add new record (invoice data)

How can i combine these two functions?
 

Isaac

Lifelong Learner
Local time
Today, 15:12
Joined
Mar 14, 2017
Messages
8,777
One idea would be to use the same (order form), but either open it acFormAdd or else open not as acFormAdd and with openargs (or set recordsource immediately after opening to that ID #)
 

Ranman256

Well-known member
Local time
Today, 18:12
Joined
Apr 9, 2015
Messages
4,337
put an unbound 'find' box in your form that shows all data.
when user enters the Order# , it filters to the record. If not there, click the ADD NEW button on the record selector.

Code:
sub txtBox_afterupdate()
if isNull(txtBox) then
   me.filterOn = false
else
   me.filter = "[OrderNum]='" & txtBox & "'"
   me.filterOn = true
endif
end sub
 

bastanu

AWF VIP
Local time
Today, 15:12
Joined
Apr 13, 2010
Messages
1,402
Maybe something like this:
Code:
Dim boOrderExists As Boolean

boOrderExists = IIf(DCount("*", "[tblOrders]", "[OrderID]='" & Me.OrderID) = 0, False, True)

If boOrderExists Then
    DoCmd.OpenForm "frmYourOrderForm", , , "[OrderID]=" & Me.OrderID
Else
    DoCmd.OpenForm "frmYourOrderForm", , , , acFormAdd
End If
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:12
Joined
May 7, 2009
Messages
19,230
using OpenArgs to set the Invoice recordset.
 

Attachments

  • Orders.accdb
    460 KB · Views: 180

Users who are viewing this thread

Top Bottom