让MS Access将特定文本添加到字段中 [英] Let MS Access add specific text to a field

查看:84
本文介绍了让MS Access将特定文本添加到字段中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Access中创建了一个数据库。并且我希望在特定字段中使Access自动将文本转换为特定格式。

I've created a database in Access. and I want in a specific field to make Access automatically converts a text to specific format.

例如根据我真正需要的内容。在该字段中,每当我输入一个五位数字(例如20650)时,该访问就像这样显示"ICL00020650"。 (这是我正在工作的地方的交易参考)。而不是每次< g
class =" gr_ gr_539 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del"数据-GR-ID =" 539" ID = QUOT; 539"> II蛋白酶/ g取代;输入全文(ICL00020650),我需要Access将任意5位数转换为该格式 

For example according to what I really need. in that field each time I enter a five digit number (e.g 20650) the access show it like this "ICL00020650" (this is a transaction reference at the place I'm working for). instead of each time <g class="gr_ gr_539 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" data-gr-id="539" id="539">Ii</g> enter the full text (ICL00020650), I need Access to convert any 5 digits number to that format 

推荐答案

一个选项是制作字段a Number(Long Integer)字段并将Format属性设置为

One option is to make the field a Number (Long Integer) field and to set the Format property to

" ICL" 00000000

"ICL"00000000

Access将存储五位数编号20650,但显示为ICL00020650。

Access will store the five-digit number 20650, but display it as ICL00020650.

如果您确实希望将值存储为文本值ICL00020650,则该字段应为字段大小为11的短文本字段。

If you really want the value to be stored as the text value ICL00020650, the field should be a Short Text field with field size 11.

在用于输入/编辑记录的表单中,为绑定到该字段的文本框创建After Update事件过程。假设字段和文本框名为MyText。

In the form used to enter/edit the records, create an After Update event procedure for the text box bound to the field. Let's say the field and text box are named MyText.

Private Sub MyText_AfterUpdate()
    If IsNumeric(Me.MyText) Then
        Me.MyText = "ICL" & Format(Me.MyText, "00000000")
    End If
End Sub




代码只会转换数字条目;它将保留文本条目(因为它们已经以ICL开头)不变。


The code will only convert numeric entries; it will leave entries that are text (because they already start with ICL) unchanged.


这篇关于让MS Access将特定文本添加到字段中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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