Results 1 to 12 of 12
  1. #1
    Join Date
    Aug 2005
    Location
    Delaware
    Posts
    139

    Unanswered: More code not working

    Hello;

    Since everyone did such a good job with the previous code that did not work, I thought I would run this one by you.

    In the following code I am trying to carry forward data (CustomerAccount#) entered into one form (frm_DisputeCases), to another form (frm_subfrm_DisputeCases). Its not working. No errors, just not carring forward the account number.

    On the same form (frm_DisputeCases), I also have the need to not only carry over the account number, but the first and last name also depending on which button the user chooses (existing customer, or new customer).

    I have tried moving positions on the open and close commands, as well as the new record command, but nothing to date was successful. I suspect it has someting to do with the New Record command being last, because if I REM that out, the number carries forward, but on an existing record, which I need the form to have empty fields (new recored) to start. Any help would be appreciated.

    Thanks...

    Larry

    'Create NEW case for existing customer
    Private Sub OpenNewCase_Click()
    On Error GoTo Err_OpenNewCase_Click

    Dim stCustomerNumber As String
    Dim stMyCustomer As String

    stMyCustomer = Me![CustomerAccount#]
    MyCustomerCriteria = "[CustomerAccount#]='" & stMyCustomer & "'"
    stFormName = "frm_subfrm_DisputeCases"
    DoCmd.Close
    DoCmd.OpenForm stFormName, , , MyCustomerCriteria
    ' start new record
    DoCmd.GoToRecord , "", acNewRec


    Exit_OpenNewCase_Click:
    Exit Sub

    Err_OpenNewCase_Click:
    MsgBox Err.Description
    Resume Exit_OpenNewCase_Click

    End Sub

  2. #2
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    You will want to get familiar with the other parameters in the OpenForm method. The parameter after the Where condition allows you to open the form on a new record using acFormAdd. Then the last parameter, OpenArgs, allows you to pass any string you want to it. I have used this in the past to populate a form with 'defaults' (ideal for firstname and lastname).

    I typically use it with an uncommon delimiter like ~ or `. Then add some code in the other form to interpret the results. You can use InStr or Split to determine where the delimiter is and then update your fields.

  3. #3
    Join Date
    Aug 2005
    Location
    Delaware
    Posts
    139
    Hello DCKunkle... Thanks for the reply;

    I adapted the code as follows below, however it did not carry over the account number. It did however eliminate the need for the seperate new record command.

    The help file on this subject (OpenForm and OpenArgs) seemed to be directed to those who want to open the new form on a specific record. That is not what I need in this case. All I need to do is carry forward a string(s) of text to a new record. Seems pretty simple but I can't make it happen.

    I also attempted the command in the help file "DoCmd.OpenForm "Employees", , ,"LastName = 'King'" (changing the LastName = 'King'" of course) however that failed also. Could you direct me to a better example of carring forward simple string data from one form to another? Is the fact that I close the first form prior to opening the second form causing an additional problem?

    Thanks...

    Larry

    'Create NEW case for existing customer
    Private Sub OpenNewCase_Click()
    On Error GoTo Err_OpenNewCase_Click

    Dim stCustomerNumber As String
    Dim stMyCustomer As String

    stMyCustomer = Me![CustomerAccount#]
    MyCustomerCriteria = "[CustomerAccount#]='" & stMyCustomer & "'"
    stFormName = "frm_subfrm_DisputeCases"
    DoCmd.Close
    DoCmd.OpenForm stFormName, , , acFormAdd, , , MyCustomerCriteria


    Exit_OpenNewCase_Click:
    Exit Sub

    Err_OpenNewCase_Click:
    MsgBox Err.Description
    Resume Exit_OpenNewCase_Click

    End Sub

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    docmd.openform "strformname",,,,,"Fred"
    should do the job.

    did you forget to 'manually' pick up the openargs?
    e.g. in strformname form_open or form_load or wherever you like
    me.mytextbox = me.openargs

    izy
    currently using SS 2008R2

  5. #5
    Join Date
    Aug 2005
    Location
    Delaware
    Posts
    139
    Thanks IZYRider;

    Problems. Here is the code I placed in the on-click event of the frm_DisputeCases:

    DoCmd.OpenForm "frm_subfrm_DisputeCases", , , , acFormAdd, , "CustomerAccount#" DoCmd.Close "frm_DisputeCases"

    And the code I placed in the on_open event of frm_subfrm_DisputeCases:

    Private Sub Form_Open(Cancel As Integer)

    Me.CustomerAccount# = Me.OpenArgs
    If IsNull(OpenArgs) Then
    MsgBox "OpenArgs contains no data", vbOKCancel
    End If

    End Sub

    When clicking the button to open frm_subfrm_DisputeCases I receive the error of: The OpenForm action was cancelled.

    If I open the frm_subfrm_DisputeCases manually, I receive an error stating: Method or Data member not found. Because of the pound sign (#) I tried brackets, quotes, quotes and brackets, but all that seemed to make no difference.

    Your thoughts?

    Larry

  6. #6
    Join Date
    Aug 2005
    Location
    Delaware
    Posts
    139
    Thanks IZYRider;

    Problems. Here is the code I placed in the on-click event of the frm_DisputeCases:

    Private Sub bla,bla,bla

    DoCmd.OpenForm "frm_subfrm_DisputeCases", , , , acFormAdd, , "CustomerAccount#"
    DoCmd.Close "frm_DisputeCases"

    And the code I placed in the on_open event of frm_subfrm_DisputeCases:

    Private Sub Form_Open(Cancel As Integer)

    Me.CustomerAccount# = Me.OpenArgs
    If IsNull(OpenArgs) Then
    MsgBox "OpenArgs contains no data", vbOKCancel
    End If

    End Sub

    When clicking the button to open frm_subfrm_DisputeCases I receive the error of: The OpenForm action was cancelled.

    If I open the frm_subfrm_DisputeCases manually, I receive an error stating: Method or Data member not found. Because of the pound sign (#) I tried brackets, quotes, quotes and brackets, but all that seemed to make no difference.

    Your thoughts?

    Larry

  7. #7
    Join Date
    Aug 2005
    Location
    Delaware
    Posts
    139
    Hello;

    Here is an example of what I'm trying to do. Trying to pass data entered into data 1,2,& 3 on form 1, to data 4,5,& 6 on form 2. Any help getting this working would be greatly appreciated. When working, I think this one would be one for the code bank. In researching this it seems like there are a lot of questions out there about this issue, however not many clear answers, at least for the non-professional.

    Thanks...

    Larry
    Attached Files Attached Files

  8. #8
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    What is CustomerAccount#? Is it a local or form level variable on Form #1? I'm getting confused as to which form you're operating in ... This is straight forward for passing data from 1 form to another. Just make a hidden textbox on 1 form and populate with data desired and pull it from the 2nd form or use the OpenArgs method as noted ... Ex:

    In your Form Open ...

    dim params() as string

    If IsNull(Me.OpenArgs) then
    Else
    params=split(Me.OpenArgs,"|",VBtextcompare)
    endif

    ' Assign variables to the array elements ...
    WhatEverVariable=params(0)

    NOTE: I like to use the pipe symbol | for my token - It's hardly ever used.
    Back to Access ... ADO is not the way to go for speed ...

  9. #9
    Join Date
    Aug 2005
    Location
    Delaware
    Posts
    139
    Hello M Owen;

    CuatomerAccount# is the old example code (real project). I thought I would make it easier with the "CarryForward" attachment. If I can get the "CarryForward" example working, I pretty sure I can get the real project working.

    Larry

  10. #10
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    hi Larry,

    couple of things.

    you are trying to pass the value of a field on your form, so drop the quotes (otherwise you pass the literal text 'Me.blahblah' not the field value)

    you are trying to stuff the args into a form field at _open when the form has not yet loaded. try again in _load.
    check out the event sequence when a when a form is opened.

    revised zip below (don't panic with the error msgs - let it run)

    izy
    Attached Files Attached Files
    currently using SS 2008R2

  11. #11
    Join Date
    Aug 2005
    Location
    Delaware
    Posts
    139
    Thanks Izy... it works great. Now... can I pass all three fields to form Two? Don't give me the code just yet... I just want to know if I'm banging my head against the wall trying to do the impossible.

    Thanks...

    Larry

  12. #12
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    sure you can.

    bundle all three values into a single string variable using an 'unnatural' separator between them (see Mike's above suggestion of using the pipe character) so you end up with a string something like "this¦and¦that"
    use that string var as your args
    then back to Mike's post again to split() the three separate values into an array.
    the first element of the array will be WhateverYouCalledIt(0)
    feed the array values into your form.

    izy
    currently using SS 2008R2

Posting Permissions

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