Convert Excel Formula to Access Code

foxhound

Board Regular
Joined
Mar 21, 2003
Messages
182
Hello,

Can anyone tell me how to accomplish this in Access code where C4 = rst!mailingname?

=RIGHT(C4,(LEN(C4)-FIND(",",C4,1)))

Thanks for any assistance.

Foxhound
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Let's say the new string is strResult.

Code:
With rst
  .MoveFirst 'Go to first record
  Do Until .EOF
  strResult=RIGHT(![mailingname],(LEN(![mailingname])-FIND(",",![mailingname],1))) 
  'Do something with strResult here...
  .MoveNext
  Loop
End With
Note: You may need to use INSTR instead of FIND.

If you want to write the result to another field in the same recordset, you could do this:

Code:
With rst
  .MoveFirst 'Go to first record
  Do Until .EOF
  .Edit
  ![MyField]=RIGHT(![mailingname],(LEN(![mailingname])-FIND(",",![mailingname],1))) 
  .Update
  .MoveNext
  Loop
End With

Alternatively, you could create a query with an expression that does the work for you. Then just use the result of the query for downstream processing. Advantage: everything updates as you need it, no need to store the calculated data.

Denis
 
Upvote 0
Denis, thanks for your help. I tried this changing find to instr but I still cannot get to work. My database does not like the "right" piece of the code. Is there a specific library that needs to be referenced in order for this function to work?


Foxhound
 
Upvote 0
If you'd taken the InStr() function advice you were given and looked it up in the Help files you'd have seen that all you had to do was change the order of the arguments.


=RIGHT(rs.Fields("MailingName"),(LEN(rs.Fields("MailingName"))-InStr(1, rs.Fields("MailingName"), ","))
 
Upvote 0

Forum statistics

Threads
1,221,581
Messages
6,160,630
Members
451,661
Latest member
hamdan17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top