Message on a Form

A

alex

Hello All,

Using Access ’03…

I’ve been trying to figure out how to display multiple messages on a
form (e.g., in a textbox, listbox, or something else).

My form contains checkboxes that hide/unhide columns on a subform (the
value of each checkbox is stored in a table and differs per record).
Based on the value of each/any checkbox, I’d like to display a line of
text letting the user know the SQL code that he/she is writing behind
the scenes…[the user populates the subform that’s compared against
another table, so in essence they’re writing the where clause]

I’ve been able to do this in a textbox, but I need multiple lines
(multiple sentences) should the user have > 1 checkbox checked.

I tried using labels (which worked) but I had them popping up all over
the form.
I tried using a case statement…no luck.
I tried using a query but I couldn’t figure out how to relate the
value of the checkbox to the actual record displayed on the form.

Any solution would need to evaluate itself (maybe on current, or after
update) after each record change because the checkbox value will
change.

Any thoughts?
alex
 
D

Douglas J. Steele

Dim strMessage As String

If Me.Checkbox1 = True Then
strMessage = strMessage & "Checkbox1 is checked." & vbCrLf
End If

If Me.Checkbox2 = True Then
strMessage = strMessage & "Checkbox2 is checked." & vbCrLf
End If

If Me.Checkbox\3 = True Then
strMessage = strMessage & "Checkbox3 is checked." & vbCrLf
End If

MsgBox strMessage

In fact, if your checkbox are simply numbered like that, you could use

Dim intLoop As Integer
Dim strMessage As String

For intLoop = 1 To 3
If Me.Controls("Checkbox" & intLoop = True Then
strMessage = strMessage & "Checkbox" & intLoop & " is checked." &
vbCrLf
End If
Next intLoop

MsgBox strMessage

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Hello All,

Using Access ’03…

I’ve been trying to figure out how to display multiple messages on a
form (e.g., in a textbox, listbox, or something else).

My form contains checkboxes that hide/unhide columns on a subform (the
value of each checkbox is stored in a table and differs per record).
Based on the value of each/any checkbox, I’d like to display a line of
text letting the user know the SQL code that he/she is writing behind
the scenes…[the user populates the subform that’s compared against
another table, so in essence they’re writing the where clause]

I’ve been able to do this in a textbox, but I need multiple lines
(multiple sentences) should the user have > 1 checkbox checked.

I tried using labels (which worked) but I had them popping up all over
the form.
I tried using a case statement…no luck.
I tried using a query but I couldn’t figure out how to relate the
value of the checkbox to the actual record displayed on the form.

Any solution would need to evaluate itself (maybe on current, or after
update) after each record change because the checkbox value will
change.

Any thoughts?
alex
 
A

alex

Dim strMessage As String

  If Me.Checkbox1 = True Then
    strMessage = strMessage & "Checkbox1 is checked." & vbCrLf
  End If

  If Me.Checkbox2 = True Then
    strMessage = strMessage & "Checkbox2 is checked." & vbCrLf
  End If

  If Me.Checkbox\3 = True Then
    strMessage = strMessage & "Checkbox3 is checked." & vbCrLf
  End If

  MsgBox strMessage

In fact, if your checkbox are simply numbered like that, you could use

Dim intLoop As Integer
Dim strMessage As String

  For intLoop = 1 To 3
    If Me.Controls("Checkbox" & intLoop = True Then
      strMessage = strMessage & "Checkbox" & intLoop & " is checked." &
vbCrLf
    End If
  Next intLoop

  MsgBox strMessage

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)


Hello All,

Using Access ’03…

I’ve been trying to figure out how to display multiple messages on a
form (e.g., in a textbox, listbox, or something else).

My form contains checkboxes that hide/unhide columns on a subform (the
value of each checkbox is stored in a table and differs per record).
Based on the value of each/any checkbox, I’d like to display a line of
text letting the user know the SQL code that he/she is writing behind
the scenes…[the user populates the subform that’s compared against
another table, so in essence they’re writing the where clause]

I’ve been able to do this in a textbox, but I need multiple lines
(multiple sentences) should the user have > 1 checkbox checked.

I tried using labels (which worked) but I had them popping up all over
the form.
I tried using a case statement…no luck.
I tried using a query but I couldn’t figure out how to relate the
value of the checkbox to the actual record displayed on the form.

Any solution would need to evaluate itself (maybe on current, or after
update) after each record change because the checkbox value will
change.

Any thoughts?
alex

Thanks Doug for your help...I'd like the messages to appear on the
form itself (for example in a box of some kind). Can I use your code
to populate an actual object (I'm not sure where to put the code you
reference above).
alex
 
D

Doug Steele

alex said:
Thanks Doug for your help...I'd like the messages to appear on the
form itself (for example in a box of some kind). Can I use your code
to populate an actual object (I'm not sure where to put the code you
reference above).

You can set the contents of a text box (let's say txtMessage) using:

Me.txtMessage = strMessage

You can set the content of a label (let's say lblMessage) using:

Me.lblMessage.Caption = strMessage

That assumes it's a text box or label on the current form. To update it on a
different form, it would be

Forms![NameOfForm].txtMessage = strMessage

or

Forms![NameOfForm].lblMessage.Caption = strMessage
 
A

alex

Thanks Doug for your help...I'd like the messages to appear on the
form itself (for example in a box of some kind).  Can I use your code
to populate an actual object (I'm not sure where to put the code you
reference above).

You can set the contents of a text box (let's say txtMessage) using:

Me.txtMessage = strMessage

You can set the content of a label (let's say lblMessage) using:

Me.lblMessage.Caption = strMessage

That assumes it's a text box or label on the current form. To update it on a
different form, it would be

Forms![NameOfForm].txtMessage = strMessage

or

Forms![NameOfForm].lblMessage.Caption = strMessage

Thanks Doug!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top