A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

replace part of field with contents of another field



 
 
Thread Tools Display Modes
  #1  
Old September 2nd, 2004, 07:59 PM
Chip
external usenet poster
 
Posts: n/a
Default replace part of field with contents of another field

I need to replace a wildcard character ($) in one field
with the contents of the ID field in the same record. My
database is 3000+ records, so doing this by hand is not an
option - or at least not a good one. For example:

My field currently reads "$_TN.jpg" and I want the result
to be "12_TN.jpg" where "12" is the value in the ID field
of the same record.
  #2  
Old September 3rd, 2004, 12:06 PM
Douglas J. Steele
external usenet poster
 
Posts: n/a
Default

Assuming you're using Access 2002 or Access 2003, you should be able to use
the Replace function in an Update query. You'd want someting like
Replace([MyField], "$", [ID]).

This should also work in Access 2000, but if all the service packs haven't
been applied, sometimes the Replace function doesn't work in queries.
There's an easy work-around, though: write your own wrapper function that
uses the Replace function:

Function MyReplace(InputString As Variant, _
ChangeFrom As String, _
ChangeTo As String) As Variant

MyReplace = Replace(InputString, _
ChangeFrom, ChangeTo)

End Function

If you're using Access 97 or earlier, you'll have to write your own Replace
function.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"Chip" wrote in message
...
I need to replace a wildcard character ($) in one field
with the contents of the ID field in the same record. My
database is 3000+ records, so doing this by hand is not an
option - or at least not a good one. For example:

My field currently reads "$_TN.jpg" and I want the result
to be "12_TN.jpg" where "12" is the value in the ID field
of the same record.



  #3  
Old September 3rd, 2004, 03:17 PM
external usenet poster
 
Posts: n/a
Default

Doug, You are WONDERFUL!! It worked perfectly. You have
no idea how much time you just saved me. THANK YOU!!!


-----Original Message-----
Assuming you're using Access 2002 or Access 2003, you

should be able to use
the Replace function in an Update query. You'd want

someting like
Replace([MyField], "$", [ID]).

This should also work in Access 2000, but if all the

service packs haven't
been applied, sometimes the Replace function doesn't work

in queries.
There's an easy work-around, though: write your own

wrapper function that
uses the Replace function:

Function MyReplace(InputString As Variant, _
ChangeFrom As String, _
ChangeTo As String) As Variant

MyReplace = Replace(InputString, _
ChangeFrom, ChangeTo)

End Function

If you're using Access 97 or earlier, you'll have to

write your own Replace
function.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"Chip" wrote in message
...
I need to replace a wildcard character ($) in one field
with the contents of the ID field in the same record.

My
database is 3000+ records, so doing this by hand is not

an
option - or at least not a good one. For example:

My field currently reads "$_TN.jpg" and I want the

result
to be "12_TN.jpg" where "12" is the value in the ID

field
of the same record.



.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a parameter query using part of the field LORIB Running & Setting Up Queries 1 September 1st, 2004 09:06 PM
Update Part# field where is blank JUAN Running & Setting Up Queries 4 August 19th, 2004 08:54 PM
Querying Part of a Field Brian Running & Setting Up Queries 2 August 2nd, 2004 03:27 PM


All times are GMT +1. The time now is 01:49 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.