ADOlogging集编号字段无法正确传输给西class牙用户

我有一个由Excel前端控制的Access数据库。 北美有9个用户没有问题,西class牙的第10个用户有数字格式问题。

当点击一个button时,会创build一个PDF(对所有用户都有正确的格式),并创build一个数据库条目。 对于在西class牙的用户,仙分隔符将从数据库条目中删除。

我正在使用ADOlogging集来传输数据,所有值都input到Excel中的文本框控件中。 我试图分隔美元和美元字段,并添加validation,没有非数字字符input。 点击button时,它将PDF和数据库条目的美元和美分字段组合在一起。

Private Sub AmountBoxCents_AfterUpdate() If CheckValuesForNonNumbers(AmountBoxCents.Value) = True Then If IsNumeric(AmountBox.Value Then AmountBoxTotal.Value = (Left(AmountBoxCents.Value, 2)) / 100 + AmountBox.Value End If Else AmountBoxCents.Value = "" End If End Sub 

CheckValuesForNonNumbers检查刚刚更新的字段中的字母或符号。 然后IsNumeric部分检查美元金额不是空白的。

 Set cnn = New ADODB.Connection 'Connect to the Access database With cnn .Provider = "Microsoft.ACE.OLEDB.12.0;Data Source=" & dbLocation & "\" & dbName & ";Jet OLEDB:Database Password=" & DBPWord .Open dbLocation & "\" & dbName End With Set rst = New ADODB.Recordset rst.Open "tblEFTRec", cnn, adOpenKeyset, adLockOptimistic, adCmdTable With rst .AddNew .Fields("CreatedBy") = Application.UserName .Fields("CreatedOn") = Now .Fields("Trans_Amnt") = AmountBoxTotal.Value .Fields("USD_Equ") = USDBox.Value .Update End With rst.Close Set rst = Nothing cnn.Close Set cnn = Nothing 

上面的代码从tblEFTRec表中打开一个ADOlogging集,然后添加一个新logging,添加到字段,更新和closures。

这是我最好的猜测。 如果这不是解决scheme,它可能仍然有助于搞清楚:西class牙语系统使用小数点分隔符。 分配(string)值时

 AmountBoxTotal.Value = (Left(AmountBoxCents.Value, 2)) / 100 + AmountBox.Value 

它产生一个string,作为分隔符(这是很好) 编辑:或不,见下面的例子 。 现在当你这样做

 .Fields("Trans_Amnt") = AmountBoxTotal.Value 

一个string得到通过,并在某一点转换回到一倍。 我没有使用ADOlogging集的经验,但似乎这种转换正在使用a . 作为分隔符并全部放弃,因为它们只是成千上万的分隔符。 通过使用.Fields("Trans_Amnt") = CDbl(AmountBoxTotal.Value)它应该被转换回使用与以前相同的分隔符,然后传递作为一个数字,而不是一个string,应该没问题。

涉及到string时,处理外来数字格式可能会非常棘手。 例如(在我的德国系统上testing):

 AmountBoxTotal.Value = 1.5 'AmountBoxTotal now shows "1.5" AmountBoxTotal.Value = AmountBoxTotal.Value + 1 'AmountBoxTotal now shows "16" ' AmountBoxTotal.Value = 3/2 'AmountBoxTotal now shows "1.5", same behavior as above ' AmountBoxTotal.Value = "1,5" 'AmountBoxTotal now shows "1,5" AmountBoxTotal.Value = AmountBoxTotal.Value + 1 'AmountBoxTotal now shows "2.5" AmountBoxTotal.Value = AmountBoxTotal.Value + 1 'AmountBoxTotal now shows "26" ' AmountBoxTotal.Value = CStr(1.5) 'AmountBoxTotal now shows "1,5", same behaviour as above 

所以总结…我不知道。 为什么使用. 在文本框中显示数字? 我必须承认,虽然我使用德语date/时间/数字格式的Windows和Office的英文安装,所以也许这会导致更多的混淆? 我在Excel设置中select的分隔符对上述示例没有影响。

首先,你应该总是处理这样的数字,而不是string。 不知道这是什么:

 If IsNumeric(AmountBox.Value) Then AmountBoxTotal.Value = (Left(AmountBoxCents.Value, 2)) / 100 + AmountBox.Value End If 

但它当然不是最佳的方法。

然后,可以使用CCur转换一个本地化的格式化小数:

 .Fields("Trans_Amnt").Value = CCur(AmountBoxTotal.Value)