Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Case Text if Item Before Has Same Case Text 2

Status
Not open for further replies.

alexbel

Technical User
Jun 27, 2004
77
US
Hi,

I have a form which is used to add items to the test. The user clicks on Item ID's that are located in a list box of whatever items they want to appear on the test. When they click on the Item ID, the item question, possible answers, and case text are all added to one text box. There user can add as many items as they want to that same text bxo.

Here's what's added to the test:

Item Question
Possible Answers
Case Text

Sometimes the case text is the same for several items. How can I have the case text be removed if the item(s) before it have the same case text?

Thank you!

 
Well alexbel, I'm not sure how you go about adding items to the text box, here's my guess.

Private Sub ListBox_DblClick()
TextBox = TextBox & ListBox.Column(0) & ListBox.Column(1)...

So you know, which column holds the CaseText. Let's say, Column(2)..(which is 3rd column.)

Circumvent the adding of a duplicate CaseText in TextBox...


Private Sub ListBox_DblClick()
iDupe As Integer

iDupe = InStr(TextBox,ListBox.Column(2))

If iDupe > 0 Then
TextBox = TextBox & ListBox.Column(0) & ListBox.Column(1)
Else
TextBox = TextBox & ListBox.Column(0) & ListBox.Column(1) & ListBox.Column(2)
End If

Is this the idea?

Let me know, Good Luck!
 
dboulos,

Here's how I add items to the text box.

List Box's After Update code:

Code:
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[Item ID] = " & str(Nz(Me![List106], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark

Me.Text50.SetFocus
Me.Text50 = Me.Text50 & vbCrLf & Me.CaseText & vbCrLf & vbCrLf & " " & Me.ItemText & vbCrLf & vbCrLf & Me.Item_Answers
Me.Refresh
End If
End Sub

Text50 is the text box that contains the case text, item questions and the possible answers.
 
I would keep track of the most recently assigned Me.CaseText in a separate variable, and then compare the current Me.CaseText against the previous when deciding whether or not to append it to the TextBox.

You also might find it considerably faster to append the text to the text box, rather than copying it over each and every time.
Code:
Text50.SetFocus
Text50.SelStart = Len(Nz(Text50.Text, ""))
If Me.CaseText <> LastCaseText
    Text50.SelText =  vbCrLf & Me.ItemText & vbCrLf & vbCrLf & Me.Item_Answers
   LastCaseText = Me.CaseText
Else
   Text50.SelText = vbCrLf & Me.CaseText & vbCrLf & vbCrLf & " " & Me.ItemText & vbCrLf & vbCrLf & Me.Item_Answers


Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
alexbel, thank-you for the clarification, slightly off was I, LOL! ...but the general idea wuz there.

but, as you see, Cajun's example is very good & practical. And thank-you Cajun again, for showing me a useful property.
But, this leaves me again wondering, if I've understood the application correctly.
alexbel, I was wondering, according to your application, if it's necessary to keep track of all the CaseText entries, during an editing "session", or just the most recent?

My understanding is that, out of 5 entries, the 2nd & 5th may be duplicates, so only comparing the most recent, which will be the 4th, against the 5th, for examople, will not catch the "dupe".

If that is the case, you will need to search the whole text50, for all CaseText entries. Hence, the InStr Function.
But, just like Cajun said, you could use a separate variable, which holds, all CaseText entries AllCaseText = AllCaseText & ";" & Me.CaseText, (public variable of course). Then do your InStr search on that.

So again, unless I'm missing something...
If InStr(AllCaseTest,Me.CaseText) = 0 Then
Text50.SelText = vbCrLf & Me.CaseText & vbCrLf & vbCrLf & " " & Me.ItemText & vbCrLf & vbCrLf & Me.Item_Answers
AllCaseText = AllCaseText & ";" & Me.CaseText
Else
Text50.SelText = vbCrLf & Me.ItemText & vbCrLf & vbCrLf & Me.Item_Answers


If my understanding is correct alexbel, this might offer an idea or two.
 
If I'm understanding this correctly, this will split the case from the the item questions and possible answers. So in turn, there will be two text boxes, correct?

If this is the case, how can I intertwine the case text to the item questions and possible answers so that the appropriate case text ends up with the correct item question and possible answers.

Thank you!
 
alexbel said:
If I'm understanding this correctly, ...
What exactly is "this" that you're referring to?

There are not two textboxes with what I've posted.

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I guess I don't understand what all of the code does.

Code:
Text50.SetFocus
Text50.SelStart = Len(Nz(Text50.Text, ""))
If Me.CaseText <> LastCaseText
    Text50.SelText =  vbCrLf & Me.ItemText & vbCrLf & vbCrLf & Me.Item_Answers
   LastCaseText = Me.CaseText
Else
   Text50.SelText = vbCrLf & Me.CaseText & vbCrLf & vbCrLf & " " & Me.ItemText & vbCrLf & vbCrLf & Me.Item_Answers

What exactly does this do: LastCaseText = Me.CaseText?

What is LastCaseText? Is it a text box?

Thank you!
 
LastCaseText is a variable that holds the value of the most recently added Me.CaseText added to the textbox.

By saving the most recently value in a variable, then you can compare the current value of Me.CaseText with the previous value, and if they are the same, not add it to the textbox, and if not, then you would. It is specifically used to answer your question, "How can I have the case text be removed if the item(s) before it have the same case text?"

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
When the code compares the previous case with the current case, if the case is the same, after the item is added, will the LastCaseText equal the case of item 1 or would it be empty because item 2 had the same case text as item 1?

Thank you!
 
As written, LastCase will still contain the value of the first case.

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thank you Cajun and dboulos.

You helped me out a lot!
 
alexbel, just to clarify, you wrote
"if the case is the same, after the item is added"

If the case is the same, the item WILL NOT BE ADDED. but, I say this because Cajun's code, may have implied otherwise, possibly a slight oversight on his part.

If Me.CaseText <> LastCaseText 'Here, it should add case test, but doesn't?
Text50.SelText = vbCrLf & Me.ItemText & vbCrLf & vbCrLf & Me.Item_Answers
LastCaseText = Me.CaseText
Else... 'but adds it here. It shouldn't.

...in case this was causing some confusion?

also, just For the record alexbel, Cajun is using here, a property which appends a string, to a certain starting point, within another string.

so, the variable LastCaseText is empty at first. We check to see if it matches CaseTest, 1st time, obviously not, it gets appended to text50, then LastCaseText gets populated with Case text(just added). Then 2nd time, LastCaseText = CaseText(previous) & is compared with next selection, either to append or leave out. If left out, LastCaseText remains the same, else LastCaseText becomes new CaseText selection, which also gets added to Text50.

But, again, will this circumvent all dupes? Have I misunderstood your application, by assuming you need to check ALL CaseText entries?

Hope this helps, thank-you for the star!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top