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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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,216,108
Messages
6,128,872
Members
449,475
Latest member
Parik11

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