Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spliting One Field into Two

Status
Not open for further replies.

mwn1218

MIS
Jan 17, 2005
11
US
I am trying to clean up some data that a client gave us. Right now the Building and Room # are in the same field and I want to split them apart. The Room number always beigns after the first 4 characters. I was trying to write a module to do this automatically. When I run the module I get a Compile error: Variable required - can't assign to this expresstion
and it highlights: Sub RoomConverstion()

Sub RoomConverstion()

Dim rsStaff As New ADODB.Recordset
Dim intLen As Long
Dim strRoom As String
Dim strOldRoom As String

rsStaff.Open "Staff"

strRoom = ""
intLen = 4

Do Until rsStaff.EOF

strOldRoom = rsStaff![RMID]

strRoom = Right(strOldRoom, Len(strOldRoom - intLen))

rsStaff![Room #] = strRoom
Loop
End Sub


Dim rsStaff As New ADODB.Recordset
Dim intLen As Long
Dim strRoom As String
Dim strOldRoom As String

rsStaff.Open "Staff"

strRoom = ""
intLen = 4

Do Until rsStaff.EOF

strOldRoom = rsStaff![RMID]

strRoom = Right(strOldRoom, Len(strOldRoom - intLen))

rsStaff![Room #] = strRoom
Loop
End Sub

If there is anything else wrong please let me know.
 
The Room number always beigns after the first 4 characters
You may try this:
DoCmd.RunSQL "UPDATE Staff SET [Room #]=Mid(RMID,5) WHERE Len(RMID)>4"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thank you so much. It worked great. One last question... do you have any idea why that error would come up?
 
I guess you tried to open a Recordset without Connection.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top