OpenArgs Compile Error

L

Lisa

I am trying to have a command button on the form 'Customers' open the
form 'Orders' to a new record with the CustomerID information
displayed.

In the form 'Customers' I added the command button with the following
event for On Click:

Private Sub cmdEnterOrder_Click()
On Error GoTo Err_cmdEnterOrder_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Orders"
DoCmd.OpenForm (stDocName,[View As
AcFormView=acNormal],,,,[WindowMode As
AcWindowMode=acWindowNormal],[OpenArgs: = Me!CustomerID])
Exit_cmdEnterOrder_Click:
Exit Sub

Err_cmdEnterOrder_Click:
MsgBox Err.Description
Resume Exit_cmdEnterOrder_Click

End Sub

On the form 'Orders' I added the following code for On Open:

Private Sub Form_Open(Cancel As Integer)
If Me.OpenArgs & "" <> "" Then
Me!CustomerID.DefaultValue = Me.OpenArgs
End If
End Sub

When I try to use the command button I get the following error message:

Compile Error
Expected: =

I have tried playing with this but cannot determine where the error
lies. Any assistance would be GREATLY appreciated.
 
A

Amy Blankenship

Try changing
DoCmd.OpenForm (stDocName,[View As AcFormView=acNormal],,,,[WindowMode As
AcWindowMode=acWindowNormal],[OpenArgs: = Me!CustomerID])

to
DoCmd.Openform, stDocName, acNormal, , , , acWindowNormal, Me!CustomerID

HTH;

Amy
 
L

Lisa

I tried that and got the following error:
Compile Error:
Argument Not Optional

Any other help or suggestions are most appreciated! I'll keep trying
until I get it right.
 
A

Amy Blankenship

Oops try
DoCmd.Openform stDocName, acNormal, , , , acWindowNormal, Me!CustomerID

Amy Blankenship said:
Try changing
DoCmd.OpenForm (stDocName,[View As AcFormView=acNormal],,,,[WindowMode As
AcWindowMode=acWindowNormal],[OpenArgs: = Me!CustomerID])

to
DoCmd.Openform, stDocName, acNormal, , , , acWindowNormal, Me!CustomerID

HTH;

Amy

Lisa said:
I am trying to have a command button on the form 'Customers' open the
form 'Orders' to a new record with the CustomerID information
displayed.

In the form 'Customers' I added the command button with the following
event for On Click:

Private Sub cmdEnterOrder_Click()
On Error GoTo Err_cmdEnterOrder_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Orders"
DoCmd.OpenForm (stDocName,[View As
AcFormView=acNormal],,,,[WindowMode As
AcWindowMode=acWindowNormal],[OpenArgs: = Me!CustomerID])
Exit_cmdEnterOrder_Click:
Exit Sub

Err_cmdEnterOrder_Click:
MsgBox Err.Description
Resume Exit_cmdEnterOrder_Click

End Sub

On the form 'Orders' I added the following code for On Open:

Private Sub Form_Open(Cancel As Integer)
If Me.OpenArgs & "" <> "" Then
Me!CustomerID.DefaultValue = Me.OpenArgs
End If
End Sub

When I try to use the command button I get the following error message:

Compile Error
Expected: =

I have tried playing with this but cannot determine where the error
lies. Any assistance would be GREATLY appreciated.
 
L

Lisa

I am getting closer. My new problem is in the code for the form
'Orders'

While on the form 'Customers' the Control Source for the text box is
CustomerID - on the form 'Orders' the Control Source for the text box
from the 'Orders Qry' and the source is Orders.CustomerID

When I try using the command button I now get the message:
Microsoft Access cannot find the field 'Orders' referred to in your
expression

The code I currently have for the Open Form Event is:

Private Sub Form_Open(Cancel As Integer)
If Me.OpenArgs & "" <> "" Then
Me!Orders.CustomerID.DefaultValue = Me.OpenArgs
End If
End Sub

I tried changing it to Me!CustomerID.DefaultValue = Me.OpenArgs and
then got the same message with cannot find field CustomerID

Thanks for the persistance and assistance.
 
A

Amy Blankenship

Me is orders, so that might only work if you had an orders subform on your
orders form. But in most instances, it wouldn't, because the orders subform
would actually be inside a subform control that you'd have to account for in
the referencing...sometimes...if Access feels like it :)

HTH;

Amy
 
L

Lisa

Still having problems with this.
I changed the OnOpen Event to:

Private Sub Form_Open(Cancel As Integer)
If Me.OpenArgs & "" <> "" Then
Me!txtCustomerID.DefaultValue = Me.OpenArgs
End If
End Sub

As txtCustomerID is the correct name for the text box. Now when I use
the command button on the form 'Customers' the form 'Orders' does open.
However, it does NOT open to a new record with the CustomerID
information filled in (which was the original goal).

Are there any other suggestions? Once again, and again, thanks for the
support! I really appreciate the help that others offer to people like
me.
 
T

tina

in the Orders form, are you trying to set the DefaultValue property of the
*control* that CustomerID is bound to? if so, then try

Me!NameOfOrdersControl.DefaultValue = Me.OpenArgs

if you're just trying to set the value of the current record in the Orders
form, try

Me!NameOfOrdersControl = Me.OpenArgs

in either case, substitute the actual name of the control that's bound to
the Orders.CustomerID field in the form's underlying query.

and btw, do you have more than one field named CustomerID in the *query*? if
so, please post the query's SQL statement.

hth
 
A

Amy Blankenship

Try:

If Len(Me.OpenArgs) then
DoCmd.GoToRecord acNewRecord
End if

Then in the Form_Current

If Len(Me.OpenArgs) AND Me.NewRecord then
'what you have below
End If
 
L

Lisa

The query's SLQ statement is:

SELECT Orders.OrderID, Orders.CustomerID, Customers.CustomerID,
Orders.OrderDate, Orders.RequiredDate, Orders.ShipDate, Orders.ShipVia,
Orders.Freight, Customers.CompanyName, Customers.FirstName,
Customers.LastName, Customers.BillingAddress1,
Customers.BillingAddress2, Customers.BillingCity,
Customers.BillingState, Customers.PostalCode,
Customers.ShippingAddress1, Customers.ShippingAddress2,
Customers.ShippingCity, Customers.ShippingState,
Customers.ShippingPostalCode, Customers!FirstName & " " &
Customers!LastName AS MailingName, [Shipping Methods].ShipperID
FROM [Shipping Methods] INNER JOIN (Customers INNER JOIN Orders ON
Customers.CustomerID = Orders.CustomerID) ON [Shipping
Methods].ShipperID = Orders.ShipVia;


What I am trying to do is to use the command button on the form
'Customers' to open the form 'Orders' to a new record with the
CustomerID filled in. The control source for txtCustomerID is
Orders.CustomerID
 
L

Lisa

Amy,
I tried that - but have errors.

I now have:

Private Sub Form_Open(Cancel As Integer)
If Len(Me.OpenArgs) Then
DoCmd.GoToRecord acNewRecord
End If
End Sub
______________________________________________________________
Private Sub Form_Current()
If Len(Me.OpenArgs) And Me.NewRecord Then
Me!txtCustomerID.DefaultValue = Me.OpenArgs
End If
End Sub
____________________________________________________

When I try to run I receive:
Run-time error '2493':
This action requires an Object Name Argument

When I use Debug the highlighted line is
'DoCmd.GoToRecord acNewRecord

Thanks again
 
T

tina

okay, instead of using the Orders form's Open event, suggest you run the
code in the Load event, as

DoCmd.RunCommand acCmdRecordsGoToNew
If Not Me.OpenArgs = "" Then
Me!txtCustomerID = Me.OpenArgs
End If

btw, if you don't want the user to be able to see *existing* records when
the Orders form opens, you can open the form in Design view and change the
DataEntry property to Yes. if you do that, then remove the DoCmd... line
from the code above.

hth
 
A

Amy Blankenship

Sorry, didn't look it up (but you could have...seems to me you need to learn
to use your help files!)

Should be

DoCmd.GoToRecord acDataForm, "Orders", acNewRecord

When someone posts code to you that doesn't quite work, rather than wringing
your hands and posting back, you'd save yourself and us a lot of time if
you'd do a quick search of the help and see where the disconnect is.

-Amy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top