• Using strLink operator for Subform

    Author
    Topic
    #464208

    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.

    Viewing 10 reply threads
    Author
    Replies
    • #1187444

      strLink is just a variable, it doesn’t have an intrinsic meaning.

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

    • #1187452

      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

      • #1187455

        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.

    • #1187466

      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.

    • #1187467

      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.

      • #1187482

        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!)

    • #1187534

      It is hitting a ‘Compile Error’ on the FrmLink operator. I attached a screen shot.

    • #1187536

      Have you insert the line :

      Public frmLink As Form

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

    • #1187537

      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.

    • #1187539

      Public variables have to be declared at the top of the VBE editor, outside of the sub. And only once.
      Something like this :

    • #1187545

      I added that to the top of both forms, and am getting a “Type Mismatch” error on the command button ‘on_click’ code.

    • #1187547

      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.

    • #1187586

      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.

    Viewing 10 reply threads
    Reply To: Reply #1187466 in Using strLink operator for Subform

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel