Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Nov 2003
    Location
    London, Gtr London, England
    Posts
    222
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Handling #Name in VB (2000 (9.0.6926 SP3))

    I have inherited a DB which I am modifying rather than rewrite from scratch.

    I have a form, Invoices, which gets accessed by two other forms.

    The first form, Purchase Orders Enquiry (F_PURCHASE_ORDERS]), is an enquiry form which allows a user to pick a Purchase Order and then append a new invoice by calling up the Invoices form.

    The Second form, Create New Purchase Order (frmCreate_Purchase_Order) and which is new, presents the user with a blank form to enter Purchase Order details and when complete offers the user a chance to attach any invoices that may exist for said Purchase Order. This form also calls up the Invoices form.

    The Invoices form effectively uses the Purchase Order Number (and some other details) from both of the other forms. The original Invoices form has a text box, altpurchno, which links to Purchase Orders Enquiry and picks up the purchase order number with the following:-
    =[Forms]![F_PURCHASE_ORDERS]![Purch_Order_No]

    I have added another text box which links to the Create Purchase Orders form :-
    =[Forms]![frmCreate_Purchase_Order]![Purch_Order_No]

    This is where I have a problem. Depending on which form I access the Invoices form from the opposing forms text box displays #Name.
    I thought I could skip over it with VB, using the following:-

    If IsNull(Me.altpurchno) Then
    Purchase_Order_No = me.txtCreatePurchaseOrderNo

    Else

    Purchase_Order_No = Me.altpurchno

    End If

    but I get a run time error '-2147352567 (80020009):
    The value you entered isn't valid for this field.

    Debug drops me onto the statement (say the second one) which displays absolutely no value, null or otherwise for Me.altpurchno

    I've got a bit stuck as to how to handle this. Any ideas anyone?

    Cheers,

    Niven <img src=/S/confused3.gif border=0 alt=confused3 width=45 height=45>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Handling #Name in VB (2000 (9.0.6926 SP3))

    I'm not sure I understand the setup completely, but instead of using text boxes that refer to another form that may or may not be open, you could pass Purch_Order_No to the invoices form in the code that opens it. Let's say the invoices form is named frmInvoices
    <code>
    DoCmd.OpenForm FornName:="frmInvoices", OpenArgs:=Me.Purch_Order_No
    </code>
    In the On Load event of frmInvoices:
    <code>
    Private Sub Form_Load()
    If Not IsNull(Me.OpenArgs) Then
    Me.Purchase_Order_No = Me.OpenArgs
    End If
    End Sub
    </code>
    You wouldn't need the text boxes txtCreatePurchaseOrderNo and altpurchno.

  3. #3
    3 Star Lounger
    Join Date
    Nov 2003
    Location
    London, Gtr London, England
    Posts
    222
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Handling #Name in VB (2000 (9.0.6926 SP3))

    Sorry Hans, my post was prepared in somewhat of a rush.

    The text boxes were already on the Invoices form and I didn't particularly want to use them. I was having problems trying to pass the Purchase Order number to the Invoices form and these text boxes struck me as being an interesting idea. I've been through the code dropped the text boxes and think I've sorted the problem now.

    Anyway, many thanks your reply, I've looked at your suggestion which is very useful, but am unfamiliar with the Openargs function. Can you group other fields within this section? i.e. In the enlarged version of the DB I am passing three fields through to the Invoices form, not just the Purchase Order number.

    Cheers again, <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

    Niven

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Handling #Name in VB (2000 (9.0.6926 SP3))

    OpenArgs is
    (1) an argument of DoCmd.OpenForm, and
    (2) a property of a form containing the value passed to it by DoCmd.OpenArgs (if any)

    If you want to pass multiple values in DoCmd.OpenForm, you must concatenate them, for example separated by commas, then parse the value in the On Open or On Load event of the form. But this might be tedious. As an alternative, you could use global variables defined in a standard module. Set the variables before opening the invoice form, and read their values in the On Open or On Load event. You can also use these variables to pass information back to the calling form. The latter requires that you open the invoice form as a dialog (WindowMode:=acDialog) to ensure that the code pauses until the user closes the form.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •