473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Appending Strings

I need some code to append several strings together, and insert those strings
into a text box. But the insertion should only happen when a particular
check box has been checked. For instance, I might have to check boxes
(check1, check2), and a text box (text1). If check one is checked then the
text box should read "check1;" or whatever the real label would be. If both
check1 and check2 have been checked then the textbox would read: "check1;
check2".

I have been asking alot of questions. I'm new to this, but I need to learn
fast.

Any help is greatly appreciated.

Thanks,
Shannan

--
Message posted via http://www.accessmonster.com
Nov 13 '05 #1
7 3343
rkc
Shannan Casteel via AccessMonster.com wrote:
I need some code to append several strings together, and insert those strings
into a text box. But the insertion should only happen when a particular
check box has been checked. For instance, I might have to check boxes
(check1, check2), and a text box (text1). If check one is checked then the
text box should read "check1;" or whatever the real label would be. If both
check1 and check2 have been checked then the textbox would read: "check1;
check2".


Do you want the label captions on seperate lines as shown?

Do you want to remove the caption from the textbox when the
checkbox is un-selected?
Nov 13 '05 #2
Goto the design view of your form. Right click on a checkbox (don't
right click the label of the checkbox - you have to right click right on
the actual checkbox). When the dropdown menu comes up select "Build".
This brings you to a code window to the Click Event of that checkbox -
say check0_Click(). It will look something like this:

Private Sub Check0_Click()

End Sub

It is inside of this sub that you can write some code like this:

Private Sub Check0_Click()
If Check0.Value = -1 Then Text0 = "Check0"
If Check0.Value <> -1 Then Text6 = ""
End Sub

If you have a check mark in the checkbox then the string "Check0" will
get written to a control called Text0 - assuming you have a textbox
control called Text0. If the check mark is removed (Check0.Value = 0)
then the text from Text0 will also be removed per this code instruction
for example. You can make it do anything you want. If you don't want
to remove the text from Text0 if Check0 is unchecked then just remove
the line

If Check0.Value <> -1 Then Text6 = ""

HTH

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #3
rkc,

No...to your first question.
Yes...to your second question.

I have almost gotten it to work using the following code, but it won't let me
have a zero length string.

For Check box called CheckAirCleaner:

Private Sub CheckAirCleaner_Click()

If Me.CheckAirCleaner = True Then
Me.TextProblemSubcategory = (ProblemSubcategory) & "Air Cleaner;"
Else
If Me.TextProblemSubcategory.Value <> "" Then
Me.TextProblemSubcategory.Value = "NA"
End If
End If
End Sub
The next check box is coded similiarly with appropriate name changes. I was
hoping to get rid of the "NA" part and just have a blank text box when no
boxes are checked.

Right now the text box may start blank, but if I check a box like
CheckAirCleaner and then uncheck it, "Air Cleaner" is replaced with "NA"
which stays there until I manually clear it. Therefore, if I now select a
box such as CheckBearing the text box would now read "NABearing".

Thanks for your help...

Shannan

--
Message posted via http://www.accessmonster.com
Nov 13 '05 #4
rkc
Shannan Casteel via AccessMonster.com wrote:
rkc,

No...to your first question.
Yes...to your second question.

I have almost gotten it to work using the following code, but it won't let me
have a zero length string.

For Check box called CheckAirCleaner:

Private Sub CheckAirCleaner_Click()

If Me.CheckAirCleaner = True Then
Me.TextProblemSubcategory = (ProblemSubcategory) & "Air Cleaner;"
Else
If Me.TextProblemSubcategory.Value <> "" Then
Me.TextProblemSubcategory.Value = "NA"
End If
End If
End Sub


I can save you a bit of time and effort with this, but after reading
another post of yours on the same subject I think you may have a
table design problem.

Any way, paste the following code into your form's code module.
After you have done that, open your form in design view and
select all the checkboxes that you want to have the desired
behaviour. Once you have done that click the properties icon,
select the Events tab, scroll to the On Click Event and enter
=updateProblemSubcategory().

Close the property sheet and give the form a try.
'---- start of code ----
Function updateProblemSubcategory()
Dim sCaption As String
Dim sac As Access.Control

'find the caption of the label
Set sac = Screen.ActiveControl
sCaption = getLabelCaption(sac)

With Me.TextProblemSubcategory
Select Case sac.value
Case vbTrue 'add the caption
If Len(.value & vbNullString) > 0 Then
.value = .value & ";"
End If
.value = .value & sCaption
Case vbFalse 'remove the caption
.value = Replace(.value, sCaption, "")
If InStr(.value, ";;") > 0 Then
.value = Replace(.value, ";;", ";")
End If
If left$(.value, 1) = ";" Then
.value = Mid$(.value, 2)
End If
If Right$(.value, 1) = ";" Then
.value = left$(.value, Len(.value) - 1)
End If
Case Else
'nothing
End Select
End With

Set sac = Nothing
End Function

Private Function getLabelCaption(xs As Access.Control) As String
'returns the caption of the label attached
'to the control argument if it exists.

Dim ctl As Access.Control

For Each ctl In Me.Controls
If ctl.ControlType = acLabel Then
If ctl.parent.Name = xs.Name Then
getLabelCaption = ctl.Caption
Exit For
End If
End If
Next

Set ctl = Nothing
End Function

'---- end of code ----
Nov 13 '05 #5
rkc,

That worked great. Thanks for your help. Last question...Where in that code
could I change it so that spaces would be inserted between the start of a
word and a semicolon?

Thanks for your help,

Shannan

--
Message posted via http://www.accessmonster.com
Nov 13 '05 #6
rkc
Shannan Casteel via AccessMonster.com wrote:
I need some code to append several strings together, and insert those strings
into a text box. But the insertion should only happen when a particular
check box has been checked. For instance, I might have to check boxes
(check1, check2), and a text box (text1). If check one is checked then the
text box should read "check1;" or whatever the real label would be. If both
check1 and check2 have been checked then the textbox would read: "check1;
check2".

I have been asking alot of questions. I'm new to this, but I need to learn
fast.

Any help is greatly appreciated.

Thanks,
Shannan

Nov 13 '05 #7
rkc
Shannan Casteel via AccessMonster.com wrote:
rkc,

That worked great. Thanks for your help. Last question...Where in that code
could I change it so that spaces would be inserted between the start of a
word and a semicolon?


You don't want to do that. It just makes it more difficult to parse
out the single values later. As it stands if you come to your senses
and decide you want to store the values seperately all you have to
do is feed the textbox value to the Split() function.

dim v as variant
dim i as integer
v = split(Me.TextProblemSubcategory.value,";")
for i = 0 to ubound(v)
'write v(i) to the database
next
Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: MLH | last post by:
I have a query, qryAppend30DayOld260ies that attempts to append records to tblCorrespondence. When run, it can result in any of the following: appending no records, appending 1 record or appending...
9
by: Selvesteen | last post by:
Hello Gurus, I need to append a sub-string at the start of strings using C. What is the best way to achieve that? for eg : I need to append "SSL"_ before { CLASS, SEED, RANDOM } to get result...
1
by: mikemac76 | last post by:
I am trying to build a test harness to practice appending strings to an rtf string. I am doing this to simulate the string I'll be sending over the wire and receiving on the other end of an IM...
4
by: John A Grandy | last post by:
could someone explain the following to me : Appending the literal type character I to a literal forces it to the Integer data type. Appending the identifier type character % to any identifier...
18
by: Paul Roberts | last post by:
Hiya I have a string with about 300+ characters, how can i insert a line break or another character every 50 characters for the whole string? Paul Roberts
1
by: Ron Adam | last post by:
In my program I have a lot of statements that append elements, but sometimes I don't want to append the element so it requres an if statement to check it, and that requires assigning the returned...
4
by: paul_zaoldyeck | last post by:
can anyone teach me how to append to datetime data into one. the first is a date and the 2nd one is a time. the time is converted from string. thanks
0
by: nbardach | last post by:
Hope this finds everyone well. Happy New Year! I'm trying to build a Loop for a set of dropdown menus I'm inserting into a form. Basically, the client has to be able to select 1 to 20 donors...
1
by: KiddoGuy | last post by:
I am trying to build a string character by character. However, when I use the overloaded += or string.append() method, the character replaces the one before it rather than appending to it so I am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.