Retrieving string before a character

rhettblaine

New Member
Joined
Oct 3, 2013
Messages
29
Office Version
  1. 365
Platform
  1. Windows
Hello all!

I had a column in my Access table that contained this formula:

WGCategory:Left([Workgroup],Len([Workgroup])-5)

The purpose is to show only a string before a - (dash) from a column that contained the following data in a column called [Workgroup]:

[Workgroup]
xxxxx-1504
xx-xx-1504
xxx-1504
xx-1504
xxxxxxx-1504

etc.

However, this formula no longer works because of an update. It gives me the following error:
[microsoft][odbc sql server driver][sql server]invalid length parameter passed to the LEFT or SUBSTRING function. (#537)

My understanding is that it could be 2 reasons:
1) I'm not connected to the SQL Server that parent table is connected to
2) The formula is giving a negative value

Question: Is there an alternative to the formula above where I am able only to retrieve the information before "-1504"?

Thanks!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Copy and Paste the following VBA Code into a Standard Module and save the module:

Code:
Public Function cutString(ByVal strIn As String) As String
Dim strOut As String, L As Long, J As Long
L = InStrRev(strIn, "-") - 1
strOut = ""
For J = 1 To L
strOut = strOut & Mid(strIn, J, 1)
Next
cutString = strOut
End Function

Change the expression in the Query Column to:

Code:
WGCategory:cutString([Workgroup])

If the InstrRev() runs normally and your table link to SQLServer doesn't have any problem then it may work.
 
Upvote 0

Forum statistics

Threads
1,221,876
Messages
6,162,567
Members
451,775
Latest member
Aiden Jenner

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