Solved Split Fields (1 Viewer)

Isaac

Lifelong Learner
Local time
Yesterday, 19:45
Joined
Mar 14, 2017
Messages
8,777
Tried both of these queries but both returned errors:
SQL:
UPDATE tblStaff SET tblStaff.fldHouseNumber = CStr((HouseNumber([tblStaff]![fldStreet])));
SQL:
UPDATE tblStaff SET tblStaff.fldHouseNumber = CStr(Val(Left([fldStreet],InStr(1,[fldStreet]))))
WHERE (((tblStaff.fldHouseNumber) Is Null));
You missed a space
Try this

Code:
UPDATE tblStaff SET tblStaff.fldHouseNumber = CStr(Val(Left([fldstreet],InStr(1,[fldstreet]," "))))

WHERE tblStaff.fldHouseNumber Is Null and instr(1,tblStaff.fldHouseNumber," ")>0

This assumes that all of your [fldstreet] values at least have a space in them somewhere.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 22:45
Joined
May 21, 2018
Messages
8,527
This works for me fine. Assuming the first thing is street number.
Code:
Public Function GetHouseNumber(strAddress As Variant) As Variant
  If Not IsNull(strAddress) Then
     GetHouseNumber = Split(strAddress, " ")(0)
  Else
    GetHouseNumber = Null
  End If
End Function

Sql
Code:
UPDATE tblAddress SET tblAddress.HouseNumber = GetHouseNumber([address]);
 

Attachments

  • address.accdb
    604 KB · Views: 96

Kayleigh

Member
Local time
Today, 03:45
Joined
Sep 24, 2020
Messages
706
That is a great solution!
Now how do I delete the house numbers in the original field - so it displays the street name only?
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 22:45
Joined
May 21, 2018
Messages
8,527
Once you get the number into a seperate field you can do an update query using the replace function to replace the number with nothing.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 22:45
Joined
May 21, 2018
Messages
8,527
I do not see that as the solution. You already had the solution to find the house number. You need a query like
Code:
UPDATE tblAddress SET tblAddress.AddressNoNumber = Replace([addressWithNumber],[HouseNumber],"");

Look at the table and run the query. I updated a new field but you can update the existing. Safer the way I did it in case you make a mistake.
 

Attachments

  • HouseNumber.accdb
    424 KB · Views: 97

Users who are viewing this thread

Top Bottom