动态设置文本框控件表单...撇号阻碍 [英] dynamically set a textbox control form...apostrophe gets in the way

查看:57
本文介绍了动态设置文本框控件表单...撇号阻碍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我目前在子窗体中有以下代码。


如果不是rstPDAddresses.EOF而不是rstPDAddresses.BOF那么

使用rstPDAddresses

txtautoAddressID.ControlSource =" =''" &安培; Nz(!autoAddressID,"")

& "''"

txtlngAddressTypeID.ControlSource =" =''" &安培; Nz(!strAddressType,

"")& "''"

txtstrStreet.ControlSource =" =''" &安培; Nz(!strStreet,"")& "''"

txtstrStreet2.ControlSource =" =''" &安培; Nz(!strStreet2,"")& "''"

txtstrCity.ControlSource =" =''" &安培; Nz(!strCity,"")& "''"

txtstrState.ControlSource =" =''" &安培; Nz(!strState,"")& "''"

txtstrZip.ControlSource =" =''" &安培; Nz(!strZip,"")& "''"

结束

此代码一直在设置子表单文本框

值到记录集结果基于主要表格显示。


但是,当你在街道名称中引入撇号时,它将不会显示为b $ b。


txtstrStreet.ControlSource =" =''" &安培; Nz(!strStreet,"")& "


是令人讨厌的代码行。我主要是一个网络人员,所以我不是很熟悉如何在文本框中显示

撇号的解决方法。


所以当!strStreet = Ferrys Ridge RD它的工作原理。但是当!strStreet =

Ferry''s Ridge Rd它就死了。


除了告诉用户之外,必须有一个解决方法。

不在街道名称中使用撇号?我似乎找不到一个。


感谢您的帮助


-Trevor

解决方案

用2个双引号替换代码中的每个单引号。如果有一个带有双引号的街道名称,这仍然会导致问题,但是这是'b $ b稀有。


如您所知,VBA使用双引号来分隔字符串。所以,你可以'$

只是在字符串中嵌入一个双引号字符,因为VBA会认为它是/ b $ b是字符串的结尾,而不知道该做什么其余的。

约定是将字符串中的字符加倍。


所以,得到:

这个字符串有一个"字QUOT;在引号中

你会写:

"这个字符串有一个" word""在引号中

如果是最后一个单词,最后你会得到3个引号字符:

"这个字符串有一个" word"" ;"


所以,你要编码:

txtautoAddressID.ControlSource =" =""" &安培; Nz(!autoAddressID,""")

等等。


-

Allen Browne - 微软MVP。西澳大利亚州珀斯。

访问用户提示 - http:// allenbrowne.com/tips.html

回复群组,而不是mvps dot org的allenbrowne。


" Trevor" <滋****** @ gmail.com>在消息中写道

news:11 ********************* @ z14g2000cwz.googlegro ups.com ...


我目前在子表单中有以下代码。

如果不是rstPDAddresses.EOF而不是rstPDAddresses.BOF那么
使用rstPDAddresses
txtautoAddressID.ControlSource = " = '' " &安培; Nz(!autoAddressID,"")
& "''"
txtlngAddressTypeID.ControlSource =" =''" &安培; Nz(!strAddressType,
"")& "''"
txtstrStreet.ControlSource =" =''" &安培; Nz(!strStreet,"")& "''"
txtstrStreet2.ControlSource =" =''" &安培; Nz(!strStreet2,"")& "''"
txtstrCity.ControlSource =" =''" &安培; Nz(!strCity,"")& "''"
txtstrState.ControlSource =" =''" &安培; Nz(!strState,"")& "''"
txtstrZip.ControlSource =" =''" &安培; Nz(!strZip,"")& "''"
结束

这段代码一直在精心设计基于主窗体显示的子窗体文本框
值到记录集结果。

但是,当你在街道名称中引入撇号时,它根本不会显示。

txtstrStreet.ControlSource =" =''" &安培; Nz(!strStreet,"")& "

是令人讨厌的代码行。我主要是一个网络人员,所以我不熟悉如何访问在文本框中显示
撇号的解决方法。

所以什么时候!strStreet = Ferrys Ridge RD可行。但是当!strStreet =
Ferry'的Ridge Rd它就死了。

除了告诉用户不要使用之外,必须有一个解决方法。街道名称中的撇号?我似乎找不到一个。

感谢您的帮助

-Trevor



< blockquote>究竟是如何创建他想要在控件中看到

的撇号?

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

用2个双引号替换代码中的每个单引号。如果街道名称带有双引号,这仍然会导致问题,但这种情况很少见。

如您所知,VBA使用双 - 引用来分隔字符串。所以,你可以在字符串中嵌入双引号字符,因为VBA会认为它是字符串的结尾,而不知道如何处理其余部分。
约定是将字符串中的字符加倍。

所以,得到:
这个字符串有一个word字样。引号
你会写:
"这个字符串有一个" word"在引号中
如果是最后一个字,最后你会得到3个引号字符:
"这个字符串有一个" word""

所以,你要编码:
txtautoAddressID.ControlSource =" =""" &安培; Nz(!autoAddressID,""")
依旧。




糟糕。对不起。

我明白了。撇号'已经存在了。误读OP。


Hi,

I currently have the following code in a subform.

If Not rstPDAddresses.EOF And Not rstPDAddresses.BOF Then
With rstPDAddresses
txtautoAddressID.ControlSource = "=''" & Nz(!autoAddressID, "")
& "''"
txtlngAddressTypeID.ControlSource = "=''" & Nz(!strAddressType,
"") & "''"
txtstrStreet.ControlSource = "=''" & Nz(!strStreet, "") & "''"
txtstrStreet2.ControlSource = "=''" & Nz(!strStreet2, "") & "''"
txtstrCity.ControlSource = "=''" & Nz(!strCity, "") & "''"
txtstrState.ControlSource = "=''" & Nz(!strState, "") & "''"
txtstrZip.ControlSource = "=''" & Nz(!strZip, "") & "''"
End With
This code has been working wonderfully at setting the subforms textbox
values to the recordset results based on the main form display.

However, when you introduce an apostrophe into the street name, it will
not display at all.

txtstrStreet.ControlSource = "=''" & Nz(!strStreet, "") & ""

is the offending line of code. I''m mostly a web guy, so I''m not
familiar with how to get access to do a workaround for displaying
apostrophes in the text box.

So when !strStreet = Ferrys Ridge RD it works. But when !strStreet =
Ferry''s Ridge Rd it dies.

There has to be a work around for this, other than telling the users to
"not use apostrophes in street names"? I can''t seem to find one yet.

Thanks for the help

-Trevor

解决方案

Replace each single quote in your code with 2 double-quotes. This will still
cause a problem if there is a street name with a double-quote, but that''s
rarer.

As you know, VBA uses the double-quote to delimit the string. So, you can''
just embed a double-quote character in a string because VBA would think it
is the end of the string, and not know what to do with the rest. The
convention is to double-up the character in the string.

So, to get:
This string has a "word" in quotes
you would write:
"This string has a ""word"" in quotes"
If it is the last word, you end up with 3 quote characters at the end:
"This string has a ""word"""

So, you are going to code:
txtautoAddressID.ControlSource = "=""" & Nz(!autoAddressID, """)
and so on.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Trevor" <zi******@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...


I currently have the following code in a subform.

If Not rstPDAddresses.EOF And Not rstPDAddresses.BOF Then
With rstPDAddresses
txtautoAddressID.ControlSource = "=''" & Nz(!autoAddressID, "")
& "''"
txtlngAddressTypeID.ControlSource = "=''" & Nz(!strAddressType,
"") & "''"
txtstrStreet.ControlSource = "=''" & Nz(!strStreet, "") & "''"
txtstrStreet2.ControlSource = "=''" & Nz(!strStreet2, "") & "''"
txtstrCity.ControlSource = "=''" & Nz(!strCity, "") & "''"
txtstrState.ControlSource = "=''" & Nz(!strState, "") & "''"
txtstrZip.ControlSource = "=''" & Nz(!strZip, "") & "''"
End With
This code has been working wonderfully at setting the subforms textbox
values to the recordset results based on the main form display.

However, when you introduce an apostrophe into the street name, it will
not display at all.

txtstrStreet.ControlSource = "=''" & Nz(!strStreet, "") & ""

is the offending line of code. I''m mostly a web guy, so I''m not
familiar with how to get access to do a workaround for displaying
apostrophes in the text box.

So when !strStreet = Ferrys Ridge RD it works. But when !strStreet =
Ferry''s Ridge Rd it dies.

There has to be a work around for this, other than telling the users to
"not use apostrophes in street names"? I can''t seem to find one yet.

Thanks for the help

-Trevor



How, exactly, does that create the apostrophe that he wants to see
in the control?
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Replace each single quote in your code with 2 double-quotes. This will still
cause a problem if there is a street name with a double-quote, but that''s
rarer.

As you know, VBA uses the double-quote to delimit the string. So, you can''
just embed a double-quote character in a string because VBA would think it
is the end of the string, and not know what to do with the rest. The
convention is to double-up the character in the string.

So, to get:
This string has a "word" in quotes
you would write:
"This string has a ""word"" in quotes"
If it is the last word, you end up with 3 quote characters at the end:
"This string has a ""word"""

So, you are going to code:
txtautoAddressID.ControlSource = "=""" & Nz(!autoAddressID, """)
and so on.




Oops. Sorry.
I get it. The apostrophe''s already there. Misread the OP.


这篇关于动态设置文本框控件表单...撇号阻碍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆