-
float and findfirst
I have written some code to check if the value (definded as currency) selected by the user in a combo box, is present in another table, but when the value is a float (, as separator symbol) it gives the error "syntax error (comma) in expression). The variable used for the selected value is [forms]![tarieven].[combo3]
I have already tried to put that first in a variable that was defined as currency, but that didn' t help.
Does anyone know how to resolve this problem?
public Sub controle()
on error GoTo controle_error
Dim dbs as Database
Dim rst as Recordset
set dbs = CurrentDb
set rst = dbs.OpenRecordset("Tarieven", dbOpenSnapshot)
rst.FindFirst "tarief = " & [Forms]![tarieven].[Combo3] & _
" and sofinr = '" & [Forms]![tarieven].[Sofinr] & "'"
If rst.NoMatch then
MsgBox "Tarief kan niet gewijzigd of gewist worden: " & _
"Verander eerst het standaardtarief", vbOKOnly + vbSystemModal
Form.Undo
End If
controle_exit:
rst.Close
Exit Sub
controle_error:
MsgBox Err.Number & " " & Err.Description
GoTo controle_exit
End Sub
ps I already posted a message where I said that I had a problem with a combobox and currency values, but now it seems that the error wasn' t in the combobox itself
-
Re: float and findfirst
try this
rst.FindFirst "tarief = " & replace([Forms]![tarieven].[Combo3],",",".") & _
" and sofinr = '" & [Forms]![tarieven].[Sofinr] & "'"
requires VB 6 (replace).
-
Re: float and findfirst
thanks for your help.
Unfortunately I don' t have VB6
But I find it very strange that I would have to use something like that to do something very simpel.
Because the problem comes down on something like
dim test as long
long = 3,14
keeping in mind that I use the European standards (, as decimal symbol)
there hase to be an easy way to do this (I hope).
-
Re: float and findfirst
Certain conversions (like VAL(..)) assume a "." always, while others (like CSNG(..)) use the separator specified in your windows setup. You might want to look at the MSDN.COM site, or VB Help and search for data conversion info.
-
Re: float and findfirst
thank you for your reaction. I tried it out, but it don' t works.
I solved the problem now by converting the ", " with mid() in "."
myStr = [rsttest]![Standaard-tarief]
myPos = InStr(1, myStr, ",")
If myPos <> 0 then
mid(myStr, myPos, 1) = "." 'This converts "," to "."
End If
rst.FindFirst "[Tarief] = " & myStr & _
"and sofinr = '" & [Forms]![tarieven].[Sofinr] & "'"