Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 34

Thread: Add form ID to be recognized on another form

  1. #1
    VBAX Tutor
    Joined
    Jan 2005
    Location
    Greenville, SC
    Posts
    220
    Location

    Add form ID to be recognized on another form

    I have a search form.
    It finds company names of a repeat customers from a customer table TblCustomer

    If 3 choices come up,
    I want to be able to click on the one I want.
    It then opens a form we have FrmRequestForWO
    Then puts the ID number from TblCustomer to
    FrmRequestForWO
    When that is done all the appropriate fields would fill in as well ie:
    Company name, address, City, State, etc. etc.

    What code can i put to make the Id from one Go to the opening Form's ID.

    Thank you for any help,
    Michael

  2. #2
    VBAX Contributor
    Joined
    Jan 2007
    Posts
    146
    Location
    Don't think i fully understand what your asking. But from what i think i got, you should look into the openargs property of a form. Also, is your search form using a list box? If so, it makes it easy because you can get your ID through lstMyList.column(Column#) (assuming it's shown on your list box)

  3. #3
    VBAX Tutor
    Joined
    Jan 2005
    Location
    Greenville, SC
    Posts
    220
    Location
    ok,
    Let me explain clearer.
    Actually I have figured out on my search form how to get the "CAT" solution!!!!
    2nd step I need help on is...

    I have a Form called "FrmSearch"
    The FrmSearch Form has let's say 4 results on the page.
    I want to click the results I want. Let's call this "strSearchData" (This result is from a table "TblBillTo")
    After I click one of the choices, i would like a Form called "FrmRequestForWO" to open and the strSearchData would be entered in the "BillToId" field on FrmRequestForWO. And then close the FrmSearch.

    Does this make more sense?
    Michael

  4. #4
    VBAX Contributor
    Joined
    Jan 2007
    Posts
    146
    Location
    think i got it now. in frmSearch, when your opening your next form, write it like:

    DoCmd.OpenForm "FrmRequestForWO", , , , , , strSearchData

    In your frmRequestForWO form_load event write like:

    [VBA]
    public sub form_load
    dim strID as string
    strID = me.openargs
    BillToId.value = strID
    docmd.close acform, "frmSearch"
    end sub
    [/VBA]

    HTH

  5. #5
    VBAX Tutor
    Joined
    Jan 2005
    Location
    Greenville, SC
    Posts
    220
    Location
    I got this to work thanks to you!
    A couple of questions since I am learning as much as I can right now:
    1)
    What is openargs?
    2)
    What if i open the "FrmRequestForWO" without using the other form?
    It then would open without openargs, right?

    Could I bypass the openArgs part?

    Something like:

     
    Public Sub form_load Dim strID As String If OpenArgs.value = Null then Exit Sub strID = me.openargs BillToId.value = strID docmd.close acform, "frmSearch" End Sub
    I am sure it's not that simple right?
    Michael

  6. #6
    VBAX Contributor
    Joined
    Jan 2007
    Posts
    146
    Location
    yeup, it is that simple. The way i usually set up my code is using the isnull statement

    if isnull(me.openargs) then exit sub

    Openargs is basically like the input parameters for a form, similar to the input parameters of a function. Another thing you can do with openargs is pass multiple parameters using the split function. For example

    [vba]
    'Other form
    Docmd.openform "myForm", , , , , , param1 & ";" & param2

    'Loaded Form

    public sub form_load
    dim myOpenArgs as variant
    dim parameter1 as string
    dim parameter2 as string
    myOpenArgs=split(me.openargs, ";")
    parameter1 = myOpenArgs(0)
    parameter2 = myopenArgs(1)
    end sub

    [/vba]

    ps: treat openargs like any other string, int, etc. it does not have any properties attached to it (like .value)

  7. #7
    VBAX Tutor
    Joined
    Jan 2005
    Location
    Greenville, SC
    Posts
    220
    Location
    Ok I think my problem is now, the FrmRequestForWO form
    is wanting a number not the text I am transfering.

    The "BillToID" is a number (even though it shows words)

    Michael

  8. #8
    VBAX Contributor
    Joined
    Jan 2007
    Posts
    146
    Location
    you will want to use the BillToID=clng(me.openargs) which converts it to a long type

  9. #9
    VBAX Tutor
    Joined
    Jan 2005
    Location
    Greenville, SC
    Posts
    220
    Location
    Ok how and where do I do that?
    Michael

    I think it's looking for the BillToID that has a relationship to it???? Does this Matter?

  10. #10
    VBAX Contributor
    Joined
    Jan 2007
    Posts
    146
    Location
    Quote Originally Posted by daniels012

    Something like:



     
    Public Sub form_load Dim lngID As long
    If OpenArgs.value = Null then Exit Sub lngID = clng(me.openargs) BillToId.value = strID docmd.close acform, "frmSearch" End Sub



  11. #11
    VBAX Tutor
    Joined
    Jan 2005
    Location
    Greenville, SC
    Posts
    220
    Location
    Here is the code:
     
    Dim lngID As Long
        If IsNull(Me.OpenArgs) Then Exit Sub
        lngID = CLng(Me.OpenArgs)
        BillToID.Value = lngID
        DoCmd.Close acForm, "frmSearch"
    I get a type mismatch error '13

    MIchael

  12. #12
    VBAX Tutor
    Joined
    Jan 2005
    Location
    Greenville, SC
    Posts
    220
    Location
    When I am in error and I put my cursor over:
    lngID it shows 0
    If I hover over
    Me.OpenArgs it shows "SFT Construction" (the name of the company)

  13. #13
    VBAX Tutor
    Joined
    Jan 2005
    Location
    Greenville, SC
    Posts
    220
    Location
    It is on this line that the code stops:

    lngID = CLng(Me.OpenArgs)
    Michael

  14. #14
    VBAX Tutor
    Joined
    Jan 2005
    Location
    Greenville, SC
    Posts
    220
    Location
    Why? can't I get past this?

    Michael

  15. #15
    VBAX Contributor
    Joined
    Jan 2007
    Posts
    146
    Location
    In your table, does it include an ID for each company? If so, you can try the dlookup function. Here is an example:

    lngID = dlookup("[IDField]","TblCustomer","[CustomerName]= '" & me.openargs & "'"

  16. #16
    VBAX Tutor
    Joined
    Jan 2005
    Location
    Greenville, SC
    Posts
    220
    Location
    Now, no error, but!!
    nothing is showing? It has sometihng like the form was opened in the Windows bar, but my form doesn't show? Actually, I can't get the Access window to show anything but a windowed outline?

    I will have to close the file.

    This all may not be worth any of this!!
    Michael

  17. #17
    VBAX Tutor
    Joined
    Jan 2005
    Location
    Greenville, SC
    Posts
    220
    Location
    I think my file just does not want me passing data from one form to another.
    I tried to move the OpenArgs to a textbox on the form. Same results, everything just locks up?

    Michael

  18. #18
    VBAX Tutor
    Joined
    Jan 2005
    Location
    Greenville, SC
    Posts
    220
    Location
    How about this:

    I want a text box named [ChosenName] on my FrmRequestForWO to show the value in the textbox on my form FrmSearch [CoName]

    How can I do this?
    I don't think I even need code? Do I?
    Michael

  19. #19
    VBAX Tutor
    Joined
    Jan 2005
    Location
    Greenville, SC
    Posts
    220
    Location
    Actually i did this:
     
    Private Sub BillToName_Click()
    [ChosenName] = [BillToName]
    End Sub
    The problem is it erases when the form is closed. I want to copy it and have it stay in the ChosenName textbox.
    How do I do that?

    Michael

  20. #20
    VBAX Contributor
    Joined
    Jan 2007
    Posts
    146
    Location
    if you are implementing it this way. I'd do it like the following:

    [vba]
    1) docmd.openform "frmName"

    2) in your form_load function do it this way:

    public sub form_load
    myTxtBox.value= Forms!frmSearch.BilltoName.value
    docmd.close acform, "frmSearch"
    end sub
    [/vba]

    You'd also have to account for if your opening your form without frmSearch being open. ie(: if currentprojects.allforms("frmSearch").isloaded then...)

Posting Permissions

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