Populate memo field with check box

S

Steve Goodrich

I use up to 6 check boxes to populate the same memo field
When I click the first check box "Ph1" the text is entered into the memo
field on a new line "PATROL OF PHASE 1" - this works great for my needs.

I have 6 of these check boxes Ph1 to Ph6

If I check the wrong box I simply uncheck it but the text still remains in
the memo field

MY QUESTION

How do I delete just the text for the relevant check box if I uncheck It,
without deleting the other entries in the same memo field?

The code I am using is as follows.The memo field is called "Incident"

Private Sub Ph1_Click()
If Me.Ph1 = True Then
Me.Incident = Me.Incident & vbCrLf & "PATROL OF PHASE 1"
End If
End Sub

Any help would be appreciated

Steve
 
L

Linq Adams via AccessMonster.com

Untested, but try this:

Private Sub Ph1_Click()
If Me.Ph1 = True Then
Me.Incident = Me.Incident & vbCrLf & "PATROL OF PHASE 1"
Else
Me.Incident = Replace(Me.Incident,"PATROL OF PHASE 1","")
End If
End Sub

But why not simply use the checkboxes?
 
D

Dennis

The previous answer leaves a gap. Try this in the else clause (the hard coded
17 is the number of characters in the string PATROL OF PHASE 1)

Me.Incident = Left(Me.Incident, InStr(1, Me.Incident, "PATROL OF PHASE 1",
vbTextCompare) - 3) & Mid(Me.Incident, InStr(1, Me.Incident, "PATROL OF PHASE
1", vbTextCompare) + 17)
 
S

Steve Goodrich

Thanks for your reply.

I tried your suggestion but get the following error "compile error, sub or
function not defined"
when I click ok it takes me back to the code page with "Replace" highlighted
I wanted to use just the check boxes but my boss wants it in the memo field
as well!!
Is there any thing else I could try
Many Thanks
Steve
 
J

John Spencer

What version of Access? Access 2000 0r later should work (with one small
correction)

Me.Incident = Replace(Me.Incident, vbCrLf & "PATROL OF PHASE 1","")

Although you could just build the content of the memo control on the fly if
the only thing it contains are the phrases. You would not even store it in
the database.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
F

fredg

I use up to 6 check boxes to populate the same memo field
When I click the first check box "Ph1" the text is entered into the memo
field on a new line "PATROL OF PHASE 1" - this works great for my needs.

I have 6 of these check boxes Ph1 to Ph6

If I check the wrong box I simply uncheck it but the text still remains in
the memo field

MY QUESTION

How do I delete just the text for the relevant check box if I uncheck It,
without deleting the other entries in the same memo field?

The code I am using is as follows.The memo field is called "Incident"

Private Sub Ph1_Click()
If Me.Ph1 = True Then
Me.Incident = Me.Incident & vbCrLf & "PATROL OF PHASE 1"
End If
End Sub

Any help would be appreciated

Steve

Off the top of my head...

Private Sub Ph1_Click()
If Me.Ph1 = True Then
Me.Incident = Me.Incident & vbCrLf & "PATROL OF PHASE 1"
Else
Me.Incident = Replace(Me.Incident , vbCrLf & "PATROL OF PHASE 1","")
End If
End Sub
 
S

Steve Goodrich

Fred
I tried your suggestion but get the following error "compile error, sub or
function not defined"
when I click ok it takes me back to the code page with "Replace" highlighted
 
F

fredg

Fred
I tried your suggestion but get the following error "compile error, sub or
function not defined"
when I click ok it takes me back to the code page with "Replace" highlighted

It works fine for me.
What is your Access Version number?

In Access 97 or older the Replace function is not supported. You would
have to create a user defined function and search for and remove the
text using the Left(), Mid(), and Instr() functions.

For early versions of Access 2000 you would need to place the
Replace() function inside a user defined function in a module (see
below).

For later versions of Access 2000 and newer, it should work as
previously replied.

For the early Access 2000 version....
Create a new module.

Function ReplaceText(StringIn as String, RemoveThis as String) as
String
If StringIn = "" or IsNull(StringIn) Then
Exit Function
Else
ReplaceText = Replace(StringIn , RemoveThis,"")
End If
End Function

Then code the Check Box Click event:

Private Sub Ph1_Click()
If Me.Ph1 = True Then
Me.Incident = Me.Incident & vbCrLf & "PATROL OF PHASE 1"
Else
Me.Incident = ReplaceText(Me.Incident , vbCrLf & "PATROL OF PHASE 1")
End If
End Sub

You can then use the same ReplaceText function on the other check
boxes, just change the text to be removed in that Check box's Click
event.
 

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