Sub form - open unpopulated

Red6

Registered User.
Local time
Today, 15:24
Joined
Jan 9, 2003
Messages
28
Hello

I have a form called Input Orders which has a sub form called Orders Details sub form. The Input Orders form is opened via a button on my Customers form. The code for the button is shown below.


Private Sub New_Order_btn_Click()
On Error GoTo Err_New_Order_btn_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Input Orders"

stLinkCriteria = "[CustomerID]=" & "'" & Me![CustomerID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


Exit_New_Order_btn_Click:
Exit Sub

Err_New_Order_btn_Click:
MsgBox Err.Description
Resume Exit_New_Order_btn_Click

End Sub


On opening the form via the button, the customer header detail displays correctly in the main Input Orders form, as per the current customer being viewed on the Customers form.

The problem is, that I need the sub form to open unpopulated, i.e. blank, so that a new order can be inputted. What is currently happening is that the subform is showing the details of the first order placed by that customer.

Am I missing something from the code or is there a fundamental problem with what I am trying to do.

Ian
 
The following line might do what you want. Insert it in the code after you open the form.

Code:
        DoCmd.GoToRecord , , acNewRec


Hello

I have a form called Input Orders which has a sub form called Orders Details sub form. The Input Orders form is opened via a button on my Customers form. The code for the button is shown below.


Private Sub New_Order_btn_Click()
On Error GoTo Err_New_Order_btn_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Input Orders"

stLinkCriteria = "[CustomerID]=" & "'" & Me![CustomerID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec

Exit_New_Order_btn_Click:
Exit Sub

Err_New_Order_btn_Click:
MsgBox Err.Description
Resume Exit_New_Order_btn_Click

End Sub


On opening the form via the button, the customer header detail displays correctly in the main Input Orders form, as per the current customer being viewed on the Customers form.

The problem is, that I need the sub form to open unpopulated, i.e. blank, so that a new order can be inputted. What is currently happening is that the subform is showing the details of the first order placed by that customer.

Am I missing something from the code or is there a fundamental problem with what I am trying to do.

Ian
 
Dohhh !!!!!!!!!

Sorry, it's been a long day.

Just went into the properties of the sub form and changed Data Entry to Yes and it seems now to be working OK.

Perhaps this might help someone, you never know.

Off now to drown my sorrows with a glass of red wine.
 
Dohhh !!!!!!!!!

Sorry, it's been a long day.

Just went into the properties of the sub form and changed Data Entry to Yes and it seems now to be working OK.

Perhaps this might help someone, you never know.

Off now to drown my sorrows with a glass of red wine.

Good call. Your change affects the form every time it is used. If you think that you might ever want to modify an existing record, then the other method might work as an Input New method as well.

Red wine can be good for your soul.
 
Just when you think a plan is coming together - sort one problem out and then you see another.

Ref first post - button opens form OK and displays the correct customer name etc, however, it is also showing the current order number and order date rather than being blank.

The sub form is working fine now - but there is just this frustrating issue I would like to try and solve.
 

Users who are viewing this thread

Back
Top Bottom