I have an Excel spreadsheet where the user enters a code and then clicks a button. The macro takes the code and looks it up in the database to return data. The issue I am having is that the code being entered is .16225 and VBA is adding a leading zero so the query is returning "Not Found". I don't understand why it is adding the leading zero. The cell is formatted as Text and when using in my query I am using Format(). Below is the snippet of code along with a visual of how it is being interpreted.
Code:Call rsInit(rsData) rsData.Source = ("SELECT * FROM bank WHERE scode = '" & Format(Cells(xRow, xCol)) & "'") rsData.Open If rsData.EOF Then MsgBox Format(Cells(xRow, xCol)) & " is not a valid bank code in Yardi.", vbOKOnly, "Invalid Bank Code" GoTo WrongCode End If
Image showing the cell is formatted as "Text"
Image showing the error message and how it is being interpreted by VBA.
How do I get rid of the leading zero? And it's not as easy as coding to remove a leading zero. There could in fact be valid codes that do begin with a zero.
Thank you for any help you can offer!
Chrissy




Reply With Quote
