Basic Script: Replace Field data

YourLastFate

New Member
Joined
Sep 16, 2013
Messages
2
Im looking for something very simple just to replace the field data of one field based on the entry of another.
I used to know VB, not so much anymore, so here is a poorly written, multi lingual script that shows in essence what im looking to do, any/all help would be appreciated:

Code:
Fields: trans, trans_type
__________________________________________________

Private Sub trans_type_LostFocus()


 If trans_type contains (5R110) Then
  If trans_type contains (PTO) Then
   trans = "5R110 PTO"
  Else
   trans = '5R110W"
  EndIf
 EndIf

 If trans_type contains (4560) Then
  trans = "HD4560"
 EndIf


End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
One field is a part number, the other is the part name, so a 4L80EOR60BD is just a 4L80E in the other field, or 2500-29542635 is just a 2500, but the Trans Type (trans) isnt always the same number characters so i need to create something that checks for certain strings in the Part Number (trans_type) and then puts in text into the Trans Type (trans), like if it has a PTO in the part number for example.
 
Upvote 0
Possibly try this (fingers crossed):

Code:
Private Sub trans_type_LostFocus()


 If Me.trans_type.Value contains ("5R110") Then
  If Me.trans_type.Value contains ("PTO") Then
   Me.trans.Value = "5R110 PTO"
  Else
   Me.trans.Value = '5R110W"
  EndIf
 EndIf

 If Me.trans_type.Value contains ("4560") Then
  Me.trans.Value = "HD4560"
 EndIf


End Sub

You need to use Me to refer to fields in your query (which often but not necessarily correspond to textboxes containing their values). Think of Me as the form saying "My", referring to it's controls and the recordset that is bound to it.
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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