Very Simple Question!!!!

G

Guest

I am new to VBA

Question: what is the code to replace a value in a field.

eg
Let the field name to be "Fruit"

Banana to "Null"
Papaya to Apple

Note : I am Using this code in a report

Any solutions?

Thanks in advance

Kennykee
 
T

tina

try

Select Case Me!Fruit
Case "Banana"
Me!Fruit = Null
Case "Papaya"
Me!Fruit = "Apple"
End Select

hth
 
T

Tim Ferguson

Question: what is the code to replace a value in a field.
Note : I am Using this code in a report


I don't think you can change the value of the field in a report: in any
case I don't think you'd want to. Set the Controlsource of the textbox to
a custom function that you are about to write:

= RenameFruit([Fruit])

Then put this sort of thing in the Report module:


' rename the fruit
' note the use of variants so it does not
' fall over with the use Nulls
'
Public Function RenameFruit(SomeFruit As Variant) _
As Variant

If IsNull(SomeFruit) Then
RenameFruit = Null

Else
Select Case SomeFruit
' etc as suggested by Tina
Case "banana" : RenameFruit = Null
Case "papaya" : RenameFruit = "Apple"
Case Else : RenameFruit = "Yum, yum, something new!"
End Select
End If
End Function


Hope that helps


Tim F
 

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

Similar Threads


Top