vba sql update statement - can't get the format() syntax right (2 Viewers)

rincewind_wizzard

Registered User.
Local time
Today, 00:50
Joined
Feb 7, 2018
Messages
23
Hi all,

I'm trying to run the following in a module, but it doesn't like the 0000000 (I get expected: end of statement). The employee number field is text and I need to pad it with leading zeros.

'Tidy up the pay number in the tax and NI table - format to 7 places
strsql = "UPDATE tblIMPORT_NIable_Taxable_Earnings SET tblIMPORT_NIable_Taxable_Earnings.[Employee number] = Format([Employee number],"0000000");"

DoCmd.RunSQL strsql


Yours,
Paul
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:50
Joined
Oct 29, 2018
Messages
21,474
You could try:
Code:
strsql = "UPDATE tblIMPORT_NIable_Taxable_Earnings SET tblIMPORT_NIable_Taxable_Earnings.[Employee number] = '" & Format([Employee number],"0000000") & "';"
Hope that helps...
 

cheekybuddha

AWF VIP
Local time
Today, 00:50
Joined
Jul 21, 2014
Messages
2,280
Out of curiosity, what datatype is field [Employee number] ?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:50
Joined
Oct 29, 2018
Messages
21,474
You could try:
Code:
strsql = "UPDATE tblIMPORT_NIable_Taxable_Earnings SET tblIMPORT_NIable_Taxable_Earnings.[Employee number] = '" & Format([Employee number],"0000000") & "';"
Hope that helps...
On second thought, maybe more like this?
Code:
strsql = "UPDATE tblIMPORT_NIable_Taxable_Earnings SET tblIMPORT_NIable_Taxable_Earnings.[Employee number] = Format([Employee number],""0000000"");"
 

rincewind_wizzard

Registered User.
Local time
Today, 00:50
Joined
Feb 7, 2018
Messages
23
On second thought, maybe more like this?
Code:
strsql = "UPDATE tblIMPORT_NIable_Taxable_Earnings SET tblIMPORT_NIable_Taxable_Earnings.[Employee number] = Format([Employee number],""0000000"");"
Wonderful. Works fine. I thought I'd tried the extra quotes, must be imagining it.
Thanks
 

Gasman

Enthusiastic Amateur
Local time
Today, 00:50
Joined
Sep 21, 2011
Messages
14,310
I'd be interested to know if the first option worked?
The one with the concatenation?
 

Users who are viewing this thread

Top Bottom