If...Then... Text box issue

Jennacat

Registered User.
Local time
Today, 02:49
Joined
Mar 19, 2008
Messages
58
Quick question:

I have a report that lists patient comments based on different areas. The areas are entered into the database as either 1, 2 , 3, etc. or A, B, C, etc. These correspond to a section title: "Scheduling you visit"; Registration"; "Facility" and so on. On my report I have a text box that is fills in with the appropriate title according to what is in the section text box:

If me.section = "1" then
me.text10 = "Scheduling your visit"
end if

But if me.section = A then it doesn't work. Why and how do I fix it? I know there is a simple answer but I just can't find it. Thanks!
 
Quick question:

I have a report that lists patient comments based on different areas. The areas are entered into the database as either 1, 2 , 3, etc. or A, B, C, etc. These correspond to a section title: "Scheduling you visit"; Registration"; "Facility" and so on. On my report I have a text box that is fills in with the appropriate title according to what is in the section text box:

If me.section = "1" then
me.text10 = "Scheduling your visit"
end if

But if me.section = A then it doesn't work. Why and how do I fix it? I know there is a simple answer but I just can't find it. Thanks!

I believe that you could use an Or statement between two conditions to do what you want.
Code:
If ((me.section = "1") [B]Or[/B] (me.section = "A")) then
    me.text10 = "Scheduling your visit"
end if

Since there are six conditions (two sets of three), you might also want to look at using Select - Case as an alternative as well.
 
I've tried that. The problem seems to come from me.section = A. I've tried it with quotation marks and without. It doesn't seem to like letters. I get an error message stating "Compile error: Argument not optional" and it highlights section. What does that me and how do I fix it?
 
It could be that because you are using SECTION (which is a RESERVED word in Access) you are confusing Access because it is expecting something else when you mean it to be something completely different.

See here for a reference on reserved words:
http://www.allenbrowne.com/AppIssueBadWord.html
 
I've tried that. The problem seems to come from me.section = A. I've tried it with quotation marks and without. It doesn't seem to like letters. I get an error message stating "Compile error: Argument not optional" and it highlights section. What does that me and how do I fix it?




There must be more to the story than we have heard so far. I created a test, and the code works exactly as I expect it would (I get "Scheduling your visit", when the vlaue is "1", "A", or "a").
  • What is the data type for the field Section?
  • I was not sure if you meant "me" or "mean" when you said "What does that me". In the case that you meant "mean", the "me" in this case refers to the current form. Section identifies a control located on the form.
COMMENT: Then again, as Boblarson points out, I missed a possible reserved word issue. This is what I like the most about the forum. From time to time we can all learn something new.
 
Last edited:
I'm sorry. I can't spell today. I meant mean. Anyways, I tried changing the name to SectionName and now I don't get an error but I also don't get anything. Here is a bit of my code:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.SectionName = C Then
Me.Text15 = "Facility"
End If

Do I have it in the wrong place? I haven't worked on reports for almost a year and i'm a bit rusty.
End Sub
 
If you have

If Me.SectionName = C

it needs to be

If Me.SectionName = "C"

in quotes as C is not numeric, but text.
 
Oops, I missed the "" around A. Now it works. It just had a problem with that name.
Thanks!
 
Oops, I missed the "" around A. Now it works. It just had a problem with that name.
Thanks!

Glad to hear -

Yeah, reserved words can play havoc with you in many respects so having that reference to look at to check to see if you are using any is a good thing to hang onto.
 
Ok, now another problem came up. It wants to put what's for sectionName H ("Overall Assessment") in the box for C ("Facility")

If Me.SectionName = "C" Then
Me.Text15 = "Facility"
End If

If Me.SectionName = "H" Then
Me.Text15 = "Overall Assessment"
End If
 
Well, you've assigned it to the same text box (Text15).

Personally I would rename all of your text boxes to meaningful names so you can easily tell what is what.
 
Here's how I want it to look:

Section: C Facility

Comment
Comment

Section: D Care Provider

Comment
Comment

So that text box is always in the same spot. The report is grouped by section so all the comments from that section are together. I tried putting different textboxes on top of each other but it didn't work (I think that needs additional codeing? something about visible.....)
 
Here's how I want it to look:

Section: C Facility

Comment
Comment

Section: D Care Provider

Comment
Comment

So that text box is always in the same spot. The report is grouped by section so all the comments from that section are together. I tried putting different textboxes on top of each other but it didn't work (I think that needs additional codeing? something about visible.....)

You need to do this in a query and then the report's sorting and grouping will do it all for you.
 
This is going to sound dumb and I should know the answer but how do I do that?
 
I'm sorry, but that isn't what I'm going for. Here is what I want it to look like:

Question: [QuestionNum] [Text6]

Where QuestionNum = 1 and Text6 = What did you value most?

I have coding that looks like this:

If Me.QuestionNum = "1" Then
Me.Text6 = "What did you value most:"
End If
If Me.QuestionNum = "2" Then
Me.Text6 = "Comments on Activities Sessions:"
End If
If Me.QuestionNum = "3" Then
Me.Text6 = "Evaluate the following Retreat experiences:"
End If

and so on. It works a bit, but then it gets goofed up and wants to put what is for question number 5 for question number 6. How do I fix this?
 
Never mind. I figured it out. :) I'm a bit rusty.........
 

Users who are viewing this thread

Back
Top Bottom