Can't get this module to work properly with form

D

deepfreeze007

This is the module I have setup to search through a memo for the character
string "\n" and replacing it with a carriage return and line feed.

It works properly in my test form, but doesn't do anything when added to the
form I want to make the change on. The test form is using 2 unbound text
boxes, and the real form is using a queried table.


Private Sub FixDescriptionButton_Click()

Dim x As Integer
Dim TextToFix, FixedText As String

TestToFix = Me![Item Description]
FixedText = ""

If Len(TextToFix) > 0 Then

For x = 1 To Len(TextToFix)

If Mid(TextToFix, x, 2) = "\n" Then

FixedText = FixedText + vbCrLf '(Chr(13) & Chr(10))
x = x + 1

Else

FixedText = FixedText & Mid(TextToFix, x, 1)

End If

Next x

End If

Me![Fixed Description] = FixedText

End Sub
 
D

Dale Fye

1. the first step would be to confirm that the query you are using is
updatable. Open the query and try to change the values in one of the fields.
If you cannot do that , then you woun't be able to edit the data in the form.

2. In your code, you are referencing two different fields [Item
Description] and [Fixed Description]. Was that your intent, or is that what
you were doing in the test form?
 
J

John Spencer

If you are using a version later than Access 97 you might consider using
the replace function.

Me.ItemDescription = Replace(Me![Item Description],"\n",vbCrLF)



'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
D

deepfreeze007

After banging my head on this till like 0400, I looked at it again today and
realized in my test form, i was referencing the name of the control, and in
the real form, I was trying to reference the actual field. It also seems
that it won't work from an underlying query (multiple tables), so since I
only need to work with one field, I'm running the form straight from the
table (although I usually avoid this). Code now looks like this:

Dim X As Integer
Dim TextToFix, FixedText As String

TextToFix = Me![TextToFix]
FixedText = ""

If Len(TextToFix) > 0 Then

For X = 1 To Len(TextToFix)

If Mid(TextToFix, X, 2) = "\n" Then

FixedText = FixedText + vbCrLf '(Chr(13) & Chr(10))
X = X + 1

Else

FixedText = FixedText & Mid(TextToFix, X, 1)

End If

Next X

Me![TextToFix] = FixedText

End If
--------

Thanks for the reply!

~deepfreeze


Dale Fye said:
1. the first step would be to confirm that the query you are using is
updatable. Open the query and try to change the values in one of the fields.
If you cannot do that , then you woun't be able to edit the data in the form.

2. In your code, you are referencing two different fields [Item
Description] and [Fixed Description]. Was that your intent, or is that what
you were doing in the test form?

----
HTH
Dale



deepfreeze007 said:
This is the module I have setup to search through a memo for the character
string "\n" and replacing it with a carriage return and line feed.

It works properly in my test form, but doesn't do anything when added to the
form I want to make the change on. The test form is using 2 unbound text
boxes, and the real form is using a queried table.


Private Sub FixDescriptionButton_Click()

Dim x As Integer
Dim TextToFix, FixedText As String

TestToFix = Me![Item Description]
FixedText = ""

If Len(TextToFix) > 0 Then

For x = 1 To Len(TextToFix)

If Mid(TextToFix, x, 2) = "\n" Then

FixedText = FixedText + vbCrLf '(Chr(13) & Chr(10))
x = x + 1

Else

FixedText = FixedText & Mid(TextToFix, x, 1)

End If

Next x

End If

Me![Fixed Description] = FixedText

End Sub
 
D

deepfreeze007

Interesting, that seems so much easier and cleaner. I am using Access 2K3,
so I'll give that a look. I'm assuming this Replace statement will replace
(pardon the pun) my whole if..then..for..next.. loop for moving through the
text field manually?

Thanks. Will let you know how it turns out.

~deepfreeze

John Spencer said:
If you are using a version later than Access 97 you might consider using
the replace function.

Me.ItemDescription = Replace(Me![Item Description],"\n",vbCrLF)



'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

This is the module I have setup to search through a memo for the character
string "\n" and replacing it with a carriage return and line feed.

It works properly in my test form, but doesn't do anything when added to the
form I want to make the change on. The test form is using 2 unbound text
boxes, and the real form is using a queried table.


Private Sub FixDescriptionButton_Click()

Dim x As Integer
Dim TextToFix, FixedText As String

TestToFix = Me![Item Description]
FixedText = ""

If Len(TextToFix) > 0 Then

For x = 1 To Len(TextToFix)

If Mid(TextToFix, x, 2) = "\n" Then

FixedText = FixedText + vbCrLf '(Chr(13) & Chr(10))
x = x + 1

Else

FixedText = FixedText & Mid(TextToFix, x, 1)

End If

Next x

End If

Me![Fixed Description] = FixedText

End Sub
 
D

deepfreeze007

Thanks John, that worked like a champ!

~deepfreeze

John Spencer said:
If you are using a version later than Access 97 you might consider using
the replace function.

Me.ItemDescription = Replace(Me![Item Description],"\n",vbCrLF)



'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

This is the module I have setup to search through a memo for the character
string "\n" and replacing it with a carriage return and line feed.

It works properly in my test form, but doesn't do anything when added to the
form I want to make the change on. The test form is using 2 unbound text
boxes, and the real form is using a queried table.


Private Sub FixDescriptionButton_Click()

Dim x As Integer
Dim TextToFix, FixedText As String

TestToFix = Me![Item Description]
FixedText = ""

If Len(TextToFix) > 0 Then

For x = 1 To Len(TextToFix)

If Mid(TextToFix, x, 2) = "\n" Then

FixedText = FixedText + vbCrLf '(Chr(13) & Chr(10))
x = x + 1

Else

FixedText = FixedText & Mid(TextToFix, x, 1)

End If

Next x

End If

Me![Fixed Description] = FixedText

End Sub
 

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