Results 1 to 14 of 14
  1. #1
    2 Star Lounger
    Join Date
    Jun 2003
    Location
    Indiana, USA
    Posts
    141
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I have a form that uses the strLink operator, under a command button, that open a small form, used to auto-sort records based on whatever fields the user want to select. Works great, however I have the need to split my form into a main & subform format. For formatting and space limitations, I wouldl like to keep the command button on the main form. I have tried a couple different method of changing the strLink command line to try and put focus on the subform. I have tried:

    strLink = "frmSub" and strLink = Forms!MainForm!frmSub

    but neither have obviously worked. I keep getting a form cannot be located error. I search the site for "strLink" threads but there was no help available.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    strLink is just a variable, it doesn't have an intrinsic meaning.

    Could you try to explain more clearly what you want to accomplish?


  3. #3
    2 Star Lounger
    Join Date
    Jun 2003
    Location
    Indiana, USA
    Posts
    141
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Here is the current code from the main form button.

    Private Sub MultSortButton_Click()
    On Error GoTo Err_MultSortButton_Click

    DoCmd.hourglass True
    'Set Public variable to pass to form_open event of multisort form
    strLink = "frmMain"
    'Open multisort form
    DoCmd.OpenForm "frm_MultipleSortOrder"

    Exit_MultSortButton_Click:
    DoCmd.hourglass False
    Exit Sub

    Err_MultSortButton_Click:
    MsgBox "MultSortButton_Click Error: " & Err.Description, , "Form.frm_CalcSubTotals Error"
    'Call ErrorHandler Here
    Resume Exit_MultSortButton_Click

    End Sub


    It works great from the frmMain, but now I need to redirect to the frmMainSub

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You'll have to provide more information. What is strLink? A global variable? If so, do you use it in the On Open or On Load event of frm_MultipleSortOrder? If so, how? If not, what is the significance of strLink? You assign its value in the code that you posted but you don't do anything with it.


  5. #5
    2 Star Lounger
    Join Date
    Jun 2003
    Location
    Indiana, USA
    Posts
    141
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Yes, it is used in the OnOpen and also on the Sort button of the frm_MultipleSortOrder. Do you want me to post the code for those? It is quite lengthy.

  6. #6
    2 Star Lounger
    Join Date
    Jun 2003
    Location
    Indiana, USA
    Posts
    141
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hans, I attached a text file with the code for OnOpen and Sort. I am off to a meeting but will check your reply tomorrow morning. It may just be easier to move the command button to the subform and be done with it. Thanks for your help.
    Attached Files Attached Files

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Subforms are not part of the Forms collection, only main forms are.

    Instead of using a variable strLink of type String, use a variable frmLink of type Form:

    Public frmLink As Form

    In the On Click code of the command button on the main form, replace

    strLink = "frmMain"

    with

    Set frmLink = Me!frmSub.Form

    and change the code behind frm_MultipleSortOrder to that from the attached text file (I haven't been able to test it, obviously, so make a backup first!)

    [attachment=86812:Code.txt]

    Attached Files Attached Files

  8. #8
    2 Star Lounger
    Join Date
    Jun 2003
    Location
    Indiana, USA
    Posts
    141
    Thanks
    2
    Thanked 0 Times in 0 Posts
    It is hitting a 'Compile Error' on the FrmLink operator. I attached a screen shot.
    Attached Images Attached Images

  9. #9
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Have you insert the line :

    Public frmLink As Form

    Like Hans says ?
    I don't see it in the code behind the error message.
    Francois

  10. #10
    2 Star Lounger
    Join Date
    Jun 2003
    Location
    Indiana, USA
    Posts
    141
    Thanks
    2
    Thanked 0 Times in 0 Posts
    No, I missed this, sorry. I tried adding it to both forms ???, but not sure if I should have??? Also, would this go in any particular location?

    Private Sub Form_Open(Cancel As Integer)
    'Purpose: Supply the row source for the First list box on the sort order form.
    On Error GoTo Err_Form_Open

    Dim Cntrls As Controls
    Dim Cntrl As Control
    Dim rst As Recordset
    Dim strSource As String
    Dim dbCur As Database
    Public frmLink As Form

    Were I have it now, in the 'frm_MultipleSortOrder', I am getting a Compile Error - Invalid Attribute in Sub or Function.

  11. #11
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Public variables have to be declared at the top of the VBE editor, outside of the sub. And only once.
    Something like this :

    [attachment=86825ublic.jpg]
    Attached Images Attached Images
    Francois

  12. #12
    2 Star Lounger
    Join Date
    Jun 2003
    Location
    Indiana, USA
    Posts
    141
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I added that to the top of both forms, and am getting a "Type Mismatch" error on the command button 'on_click' code.

  13. #13
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I added that to the top of both forms
    You have to declare Public variables only once. Take it away in one of the two forms.

    Can you repost the code in the button 'on click'. Without seeing it, it's impossible to say what's wrong.
    Francois

  14. #14
    2 Star Lounger
    Join Date
    Jun 2003
    Location
    Indiana, USA
    Posts
    141
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Sorry for the delay, had to go on a "call". I got the problem solved. I deleted one of the Public variables. I appreciate your's and Hans assistance.

Posting Permissions

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