Page 1 of 3 123 LastLast
Results 1 to 15 of 39
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Text boxes' visible property

    I have a report whose Record Source is set to a query (<font color=red>qryprodgio</font color=red>).
    The Format event of the Detail section goes:

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    rst.Open "<font color=red>qryprodgio</font color=red>", cnn, adOpenKeyset, adLockOptimistic
    If rst!powerday > Forms!mask1!Text25 * 1000 Then
    Reports!prodgio!Text36.Visible = True
    Reports!prodgio!Text36 = "more than " & Forms!mask1!Text25 & "MW"
    Else
    If rst!powerday < Forms!mask1!Text23 * 1000 Then
    Reports!prodgio!Text36.Visible = True
    Reports!prodgio!Text36 = "less than " & Forms!mask1!Text23 & "MW"
    End If
    End If
    rst.Close
    End Sub

    Even when I purposefully set the values in text23 or text25 in order to set off the if condition, I can never see Text36's content in the report.
    What's wrong?

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Text boxes' visible property

    Stick a couple of unbound textboxes on your report and use code in the report's open event to set the text boxes equal to Forms!mask1!Text25 and Forms!mask1!Text23, then reference the textboxes in your code. You may have to leave the textboxes visible but set their forecolor and backcolor to white to hide them.
    Charlotte

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text boxes' visible property

    I stuck 2 unbound text boxes in the report (page header section), named them Potmax and Potmin and used:
    Private Sub Report_Open(Cancel As Integer)
    Reports!prodgio!Potmax = Forms!mask1!Text25
    Reports!prodgio!Potmin = Forms!mask1!Text23
    End Sub
    But when I try to open the report, a message pops up:
    Run-time error '2448': You can't assign a value to this object.
    with the line: Reports!prodgio!Potmax = Forms!mask1!Text25 highlighted in yellow.

  4. #4
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text boxes' visible property

    Try setting the control source properties for the report controls to your form controls. Use the expression builder if you're not sure about the correct syntax. It should be something like this:

    =[Forms]![frmTest01]![txtUPCODE]

    This should work with your code in the format event.

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Text boxes' visible property

    Alternatively, put two calculated fields in your report recordsource that reference the form fields you want to use. Then you can refer the the values directly in your code.
    Charlotte

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    You know...

    The strange thing is that if I keep the line
    "If rst!powerday > Forms!mask1!Text25 * 1000 Then"
    as it originally was in my first message,
    everything runs smoothly but for the fact that the contents of text36 doesn't show. But if I apply your advice and change the line to
    "If rst!powerday > Reports!prodgio!Potmax * 1000 Then"
    after having set Potmax's control source =[Forms]![mask]![text25]
    the code stops at this line(If rst!powerday > Reports!prodgio!Potmax * 1000 Then) with a message box saying, "Run-time error '2447': There is an invalid use of the .(dot) or ! operator or invalid parentheses."

  7. #7
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Stick and stones will break Access' bones...

    But they won't make it show that darn text box in the report <img src=/S/humpty.gif border=0 alt=humpty width=15 height=15>.
    Putting two calculated fields in my report record source that reference the form fields I want to use gives me this:

    Private Sub Report_Activate()
    Set cnn = CurrentProject.Connection
    Dim cmd As New ADODB.Command
    cat.ActiveConnection = CurrentProject.Connection
    cmd.CommandText = "SELECT Id, anno, mese, giorno, " & _
    Forms!mask1!List11 & " as selectedfield, selectedfield/24 as powerday, " & Forms!mask1!Text23 _
    & " as powermin, " & Forms!mask1!Text25 & " as powermax FROM mediegio"
    With cat.Views
    '.Append "qryProdGIO", cmd
    .Item("qryProdGIO").Command = cmd
    End With
    Set cmd = Nothing
    End Sub

    and now here's how
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    rst.Open "qryprodgio", cnn, adOpenKeyset, adLockOptimistic
    If rst!powerday > rst!powermax * 1000 Then
    Reports!prodgio!Text36.Visible = True
    Reports!prodgio!Text36 = "more than " & Potmax & " MW"
    Else
    If rst!powerday < rst!powermin * 1000 Then
    Reports!prodgio!Text36.Visible = True
    Reports!prodgio!Text36 = "less than " & Potmin & " MW"
    End If
    End If
    rst.Close
    End Sub
    looks like.
    Still the report won't show text36's contents for any record.

  8. #8
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text boxes' visible property

    Even putting
    Private Sub Corpo_Format(Cancel As Integer, FormatCount As Integer)
    rst.Open "qryprodgio", cnn, adOpenKeyset, adLockOptimistic
    If rst!powerday > rst!powermax * 1000 Then
    Reports!prodgio!Text36.Visible = True
    Reports!prodgio!Text36 = "more than " & <font color=red>rst!powermax </font color=red>& " MW"
    Else
    If rst!powerday < rst!powermin * 1000 Then
    Reports!prodgio!Text36.Visible = True
    Reports!prodgio!Text36 = "less than " & <font color=red>rst!powermin </font color=red>& " MW"
    End If
    End If
    rst.Close
    End Sub
    Doesn't change the outcome.

  9. #9
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text boxes' visible property

    I like that even better!

  10. #10
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text boxes' visible property

    Hard to tell from here what exactly is causing the breakdown. I'd be curious to hear what the actual flow looks like if you put in a break point and went through the code line by line. That might help give us a clue where to focus our attention.

  11. #11
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Text boxes' visible property

    Hi,
    I think your problem may be that you are opening a recordset based on qryprodgio (when your report is already bound to qryprodgio) but you're never moving through the recordset so rst!powerday always refers to the same record.) Assuming that powerday appears in your report, you could use something like the following:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    With Me
    If !powerday > Forms!mask1!Text25 * 1000 Then
    !Text36.Visible = True
    !Text36 = "more than " & Forms!mask1!Text25 & "MW"
    Else
    If !powerday < Forms!mask1!Text23 * 1000 Then
    !Text36.Visible = True
    !Text36 = "less than " & Forms!mask1!Text23 & "MW"
    End If
    End If
    End With
    End Sub
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  12. #12
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    We're almost there...

    I've implemented your Sub Detail_Format word for word and now the code stops at the line that sets the value of Text36:
    !Text36 = "more than " & Forms!mask1!Text25 & "MW" or
    !Text36 = "less than " & Forms!mask1!Text23 & "MW"
    depending on which if condition is set off, with the message:"Run-time error '2448': You can't assign a value to this object."

  13. #13
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Scrap my last message to you

    The error message was due to the fact that Text36's Control Source property was put =Powerday instead of being empty(oops!Mea culpa).
    But there's another problem:
    When the code runs and one of the if conditions occurs, Text36 remains forever visible with the message contained in that particular if condition, so basically if we say that the second if condition becomes true, the report shows the message "less than .4 MW" for all the lines from then on.

  14. #14
    Lounger
    Join Date
    Apr 2001
    Location
    Stuttgart, Germany
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Scrap my last message to you

    That's because you never reset the Visible property for the case neither of the conditions is true. Put a line before the IF-Statement:

    with me
    !Text36.Visible = false '!!!!!!!!!!
    If !powerday > Forms!mask1!Text25 * 1000 Then
    !Text36.Visible = True
    !Text36 = "more than " & Forms!mask1!Text25 & "MW"
    Else
    If !powerday < Forms!mask1!Text23 * 1000 Then
    ...
    end with
    Cheers
    Emilia

  15. #15
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Welcome aboard Emilia!

    I guess I needed fresh blood to get out of it <img src=/S/joy.gif border=0 alt=joy width=23 height=23>.
    The table Mediegio, which through qryProdGio feeds data to the text boxes in the detail section, actually is made up of more than a thousand records, so this two events(falling below Forms!mask1!Text23 or rising above Forms!mask1!Text25) are bound to happen many times if I set the value of Text23 or Text25 low or high enough respectively. Well, because of this and any time either event occurs, I'd like the actual message to read, "less than [text23.value] kW n.Y" or "more than [text25.value] kW n.Z" where Y or Z is incrementing each time either event occurs.
    How can I can I count the times either event occurs and display it in the Text36 text box?

Page 1 of 3 123 LastLast

Posting Permissions

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