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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vba to move from one cell to the other

Status
Not open for further replies.

mp3er3000

Programmer
Feb 19, 2005
17
US
ID NAME PHONE1 PHONE2
1 KEVIN 911 988
2 TOM 897
3 LISA 485 485

Above is my table, I would like to write a vba script to check if phone1 is blank then move phone2 value to phone1. Can anyone please help me? Thanks
the end result should look like this


ID NAME PHONE1 PHONE2
1 KEVIN 911 988
2 TOM 897
3 LISA 485 485
 
You can do this with an update query:
Code:
UPDATE tblMyTable SET tblMyTable.Phone1 = [tblMyTable].[Phone2], tblMyTable.Phone2 = Null
WHERE tblMyTable.Phone1 Is Null AND tblMyTable.Phone2 Is Not Null;
Or if you want to do it in VBA:
Code:
Dim strSQL As String

strSQL = "UPDATE tblMyTable " _
& "SET tblMyTable.Phone1 = [tblMyTable].[Phone2], tblMyTable.Phone2 = Null " _
& "WHERE tblMyTable.Phone1 Is Null AND tblMyTable.Phone2 Is Not Null;"

DoCmd.RunSQL strSQL
HTH,

Ken S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top