vba help

rob1234

Registered User.
Local time
Today, 08:27
Joined
Aug 16, 2005
Messages
25
I'm writing a VBA function that removes any extra whitespace from text fields and I want to pass to that function the name of the field in a string. The problem I'm having is I have a recordset 'rsUpdate' and a string 'field' containing the field name and I want to do something like rsUpdate!field = [string with whitespace removed] but when I do this it looks for the field named field in the recordset and not the field whose name is equal to the value in the string 'field'. Is there a way to do this? I'm fairly new to VBA. Thanks.
 
How about:
rsUpdate!field = fRemoveWhiteSpace(rsUpdate!field)
 
So in your code I assume field is the name of a field in the table and not a string containing the name of the field. Is rsUpdate!field just a string so I can remove the whitespace from it in fRemoveWhiteSpace, return it, and do rsUpdate.update to update the record. so assuming I have a field named lastname in the table I can do:

rsUpdate.lastname = fRemoveWhiteSpace(rsUpdate!lastname)
rsUpdate.update
...

public function fRemoveWhiteSpace(field as string)
'code to remove white space here
 

Users who are viewing this thread

Back
Top Bottom