Consulting

Results 1 to 6 of 6

Thread: Solved: Visible vs. invisible

  1. #1
    VBAX Regular
    Joined
    Sep 2005
    Posts
    44
    Location

    Solved: Visible vs. invisible

    I have a form Products and I need it to show a couple of controls (buttons actually) only when in editing mode.
    The form opens always in View only unless you click the button 'Edit_Products'. This is my code:
    [VBA]
    Private Sub Edit_Products_Click()
    On Error GoTo Err_Edit_Products_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Products"
    stLinkCriteria = "[ProductId] =" & Me![ProductId]
    DoCmd.Close
    DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit
    MkProduct.Visible = True
    SvProduct.Visible = True
    DltProduct.Visible = True

    Exit_Edit_Products_Click:
    Exit Sub

    Err_Edit_Products_Click:
    MsgBox Err.Description
    Resume Exit_Edit_Products_Click

    End Sub
    [/VBA]

    When I click it, it says that the expression refers to an object that is closed or that doesn't exist. I checked the names over and over and they are ok. ?.?
    Help, pls

  2. #2
    I was able to duplicate this error and found your problem. When you close the form before reopening it, the references to the form and its controls are removed from memory and you can no longer access them implicitly.

    Instead, you can reference these controls explicitly by adding the form's identifier, like so:
    [VBA]
    Forms(stDocName).MkProduct.Visible = True
    Forms(stDocName).SvProduct.Visible = True
    Forms(stDocName).DltProduct.Visible = True
    [/VBA]

    Alternatively, you could also declare a Form variable and reference commands this way:
    [VBA]
    Dim f as Form
    DoCmd.OpenForm stDocName, , , , acFormEdit
    Set f = Forms(stDocName)
    f.MkProduct.Visible = True
    f.SvProduct.Visible = True
    f.DltProduct.Visible = True
    [/VBA]

  3. #3
    VBAX Regular
    Joined
    Sep 2005
    Posts
    44
    Location

    Thanx!!!

    It works!

    Thanks a lot!

  4. #4
    VBAX Regular
    Joined
    Sep 2005
    Posts
    44
    Location
    btw, remember the one you helped me solve about the value exists?
    This was the result that worked perfectly:

    [VBA]
    Private Sub Form_Open(Cancel As Integer)

    If IsNull(CustomerIdctrl) Then
    CustomerIdctrl.Visible = False
    SellerIdctrl.Visible = True ' No customer record
    Else
    CustomerIdctrl.Visible = True
    SellerIdctrl.Visible = False ' Customer exists
    End If
    End Sub
    [/VBA]

    Now I'm trying to use it to hide a subreport depending on the same value:

    [VBA]
    Private Sub Report_Open(Cancel As Integer)

    If IsNull(Report.SubProf_cust) Then
    Report.SubProf_cust.Visible = False
    Report.SubProf_ssel.Visible = True ' No customer record
    Else
    Report.SubProf_cust.Visible = True
    Report.SubProf_ssel.Visible = False ' Customer exists
    End If
    End Sub
    [/VBA]

    SubProf_cust and SubProf_ssel are the subreports that should hide or show. but it does nothing at all, not even an error. If I take out the "Report." that goes infront of the name, it gives me exactly the same results.

  5. #5
    No problem.

    First of all, you're not testing whether a value is Null; you're testing to see if a subreport (SubProf_cust) is Null. In the former example, pointing the IsNull function to CustomerIdctrl worked because a control such as a textbox returns the Value Property by default -- it's the same as if you had used IsNull(CustomerIdctrl.Value). In the latter case, you've entered the report object SubProf_cust as the parameter, but a report returns its Controls Collection by default, which will probably never be null. If the value that forms the basis for your condition is available in a control, point it to that control instead.

    Also, what exactly does "Report" represent? Is it the exact name of an open report, a declared variable set to an open report or form, or were you attempting to reference the Reports Collection (which is plural)?

  6. #6
    VBAX Regular
    Joined
    Sep 2005
    Posts
    44
    Location
    Yes, but that is because I'm never sure of how to build those querys for the programation. Anyway I already solved it without any vbcode. I simply made the subreports of the same size and put them on top of each other (SubProf_cust on top of course). Now when I get a customer it will block the sellers shipping info from view, just like that. It's not very scientific but it works XD

    btw, 'report' just meant report I thought I had to build the query telling th program that those where reports ^.^'

Posting Permissions

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