Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access 前导和尾随空间_Ms Access_Vba - Fatal编程技术网

Ms access 前导和尾随空间

Ms access 前导和尾随空间,ms-access,vba,Ms Access,Vba,我想到了一个有点奇怪的情况。我有一个从网页输入表单的字符串。当我尝试应用筛选器时,我注意到字符串的行为与预期不符 问题的关键在于我如何看待这根弦——它看起来不同 Form View - "523548" Datasheet View - " 523548" Raw Sql - " 523548" 实际上,当我查看数据表值时,它显示为“523548”,但复制为“523548” Asc(左(字符串),1)告诉我第一个字符是Chr9(制表键) 我真的很想知道为什么会发生这种情况,或者更重要的是,我

我想到了一个有点奇怪的情况。我有一个从网页输入表单的字符串。当我尝试应用筛选器时,我注意到字符串的行为与预期不符

问题的关键在于我如何看待这根弦——它看起来不同

Form View - "523548"
Datasheet View - "  523548"
Raw Sql - " 523548"
实际上,当我查看数据表值时,它显示为
“523548”
,但复制为
“523548”

Asc(左(字符串),1)告诉我第一个字符是Chr9(制表键)

我真的很想知道为什么会发生这种情况,或者更重要的是,我能做些什么来纠正它

谢谢


戴夫

好吧,调整你的例行程序,不包括新条目的选项卡

可以使用“替换”调整的旧条目:

我会在这里使用这个函数。虽然该链接用于Excel,但在Access中的语法相同


将值写入表时使用此函数,也可以使用此函数清理当前数据。这将删除虚拟选项卡和空格。

谢谢您的提示。我找到了这个功能,并添加了几个项目以满足我的需要

' Strip Illegal Characters
' http://www.utteraccess.com/wiki/index.php/Strip_Illegal_Characters
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
'
' You are free to use this code in any application,
' provided this notice is left unchanged.
'
' rev  date                          brief descripton
' 1.0  2010-10-23                    Writing files to disk that contain illegal file characters can cause sometimes obscure error message(s)
'
Public Function fStripIllegal(strCheck As String, Optional strReplaceWith As String = "") As String

On Error GoTo StripIllErr
'illegal file name characters included in default string are    ? [ ] / \ = + < > :; * " , '

Dim intI As Integer
Dim intPassedString As Integer
Dim intCheckString As Integer
Dim strChar As String
Dim strIllegalChars As String
Dim intReplaceLen As Integer

If IsNull(strCheck) Then Exit Function

strIllegalChars = "?[]/\=+<>:;,*" & Chr(34) & Chr(39) & Chr(32) & Chr(9)  'add/remove characters you need removed to this string

intPassedString = Len(strCheck)
intCheckString = Len(strIllegalChars)

intReplaceLen = Len(strReplaceWith)

If intReplaceLen > 0 Then   'a character has been entered to use as the replacement character

   If intReplaceLen = 1 Then   'check the character itself isn't an illegal character

       If InStr(strIllegalChars, strReplaceWith) > 0 Then
           MsgBox "You can't replace an illegal character with another illegal character", _
                  vbOKOnly + vbExclamation, "Invalid Character"
           fStripIllegal = strCheck
           Exit Function
       End If

   Else   'only one replacement character allowed

       MsgBox "Only one character is allowed as a replacement character", _
              vbOKOnly + vbExclamation, "Invalid Replacement String"
       fStripIllegal = strCheck
       Exit Function

   End If
End If

If intPassedString < intCheckString Then

   For intI = 1 To intCheckString
       strChar = Mid(strIllegalChars, intI, 1)
       If InStr(strCheck, strChar) > 0 Then
           strCheck = Replace(strCheck, strChar, strReplaceWith)
       End If
   Next intI

Else

   For intI = 1 To intPassedString
       strChar = Mid(strIllegalChars, intI, 1)
       If InStr(strCheck, strChar) > 0 Then
           strCheck = Replace(strCheck, strChar, strReplaceWith)
       End If
   Next intI

End If

fStripIllegal = Trim(strCheck)

StripIllErrExit:
Exit Function

StripIllErr:
MsgBox "The following error occured: " & err.Number & vbCrLf _
    & err.Description, vbOKOnly + vbExclamation, "Unexpected Error"

fStripIllegal = strCheck

Resume StripIllErrExit

End Function
”删除非法字符
' http://www.utteraccess.com/wiki/index.php/Strip_Illegal_Characters
“代码由UtterAccess Wiki提供
“根据知识共享许可证获得许可
' http://creativecommons.org/licenses/by-sa/3.0/
'
'您可以在任何应用程序中自由使用此代码,
"但此通知保持不变。
'
“修订日期简要说明”
'1.0 2010-10-23将包含非法文件字符的文件写入磁盘有时可能会导致错误消息模糊
'
公共函数fstripIlligal(strCheck作为字符串,可选strreplacement作为字符串=)作为字符串
关于错误转到stripiller
'默认字符串中包含的非法文件名字符是?[ ] / \ = + < > :; * " , '
作为整数的Dim intI
Dim intPassedString作为整数
Dim intCheckString作为整数
作为字符串的Dim strChar
像弦一样的暗条纹
作为整数的Dim intReplaceLen
如果为空(strCheck),则退出函数
strIllegalChars=“?[]/\=+:;”*“&Chr(34)&Chr(39)&Chr(32)&Chr(9)”添加/删除需要删除到此字符串中的字符
intPassedString=Len(strCheck)
intCheckString=Len(strIllegalChars)
intReplaceLen=Len(strReplaceWith)
如果intReplaceLen>0,则“已输入一个字符用作替换字符。”
如果intReplaceLen=1,则“检查字符本身是否为非法字符”
如果InStr(strIllegalChars,strreplacement)>0,则
MsgBox“您不能用其他非法字符替换非法字符”_
vbOKOnly+VBEQUOTE,“无效字符”
fstriplockle=strCheck
退出功能
如果结束
Else'只允许一个替换字符
MsgBox“仅允许一个字符作为替换字符”_
vbOKOnly+VBEQUOTE,“替换字符串无效”
fstriplockle=strCheck
退出功能
如果结束
如果结束
如果intPassedString0,则
strCheck=Replace(strCheck、strChar、strReplaceWith)
如果结束
下一个因蒂
其他的
对于intI=1到intPassedString
strChar=Mid(strIllegalChars,intI,1)
如果InStr(strCheck,strChar)>0,则
strCheck=Replace(strCheck、strChar、strReplaceWith)
如果结束
下一个因蒂
如果结束
fstripIlligal=修剪(strCheck)
StripIllErrExit:
退出功能
脱衣舞娘:
MsgBox“发生以下错误:”&错误号&vbCrLf_
&错误说明,vbOKOnly+VBEQUOTE,“意外错误”
fstriplockle=strCheck
退出
端函数
内置VBA-
Trim()
只修剪空格,不修剪制表符。您必须构建自己的函数才能删除制表符。
' Strip Illegal Characters
' http://www.utteraccess.com/wiki/index.php/Strip_Illegal_Characters
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
'
' You are free to use this code in any application,
' provided this notice is left unchanged.
'
' rev  date                          brief descripton
' 1.0  2010-10-23                    Writing files to disk that contain illegal file characters can cause sometimes obscure error message(s)
'
Public Function fStripIllegal(strCheck As String, Optional strReplaceWith As String = "") As String

On Error GoTo StripIllErr
'illegal file name characters included in default string are    ? [ ] / \ = + < > :; * " , '

Dim intI As Integer
Dim intPassedString As Integer
Dim intCheckString As Integer
Dim strChar As String
Dim strIllegalChars As String
Dim intReplaceLen As Integer

If IsNull(strCheck) Then Exit Function

strIllegalChars = "?[]/\=+<>:;,*" & Chr(34) & Chr(39) & Chr(32) & Chr(9)  'add/remove characters you need removed to this string

intPassedString = Len(strCheck)
intCheckString = Len(strIllegalChars)

intReplaceLen = Len(strReplaceWith)

If intReplaceLen > 0 Then   'a character has been entered to use as the replacement character

   If intReplaceLen = 1 Then   'check the character itself isn't an illegal character

       If InStr(strIllegalChars, strReplaceWith) > 0 Then
           MsgBox "You can't replace an illegal character with another illegal character", _
                  vbOKOnly + vbExclamation, "Invalid Character"
           fStripIllegal = strCheck
           Exit Function
       End If

   Else   'only one replacement character allowed

       MsgBox "Only one character is allowed as a replacement character", _
              vbOKOnly + vbExclamation, "Invalid Replacement String"
       fStripIllegal = strCheck
       Exit Function

   End If
End If

If intPassedString < intCheckString Then

   For intI = 1 To intCheckString
       strChar = Mid(strIllegalChars, intI, 1)
       If InStr(strCheck, strChar) > 0 Then
           strCheck = Replace(strCheck, strChar, strReplaceWith)
       End If
   Next intI

Else

   For intI = 1 To intPassedString
       strChar = Mid(strIllegalChars, intI, 1)
       If InStr(strCheck, strChar) > 0 Then
           strCheck = Replace(strCheck, strChar, strReplaceWith)
       End If
   Next intI

End If

fStripIllegal = Trim(strCheck)

StripIllErrExit:
Exit Function

StripIllErr:
MsgBox "The following error occured: " & err.Number & vbCrLf _
    & err.Description, vbOKOnly + vbExclamation, "Unexpected Error"

fStripIllegal = strCheck

Resume StripIllErrExit

End Function