VBA问题:是否有一种简单的方法可以修剪表中的所有字段?

问题描述:

亲爱的Access 2003用户,


有没有办法一次性修剪表中的所有字段

VBA(首选)还是查询?现在,我正在使用更新查询和

更新EACH字段到它的修剪对应物。有任何想法吗?谢谢!


Kevin

Dear fellow Access 2003 Users,

Is there a way to trim all of the fields in a table in one swoop using
VBA (preferred) or a query? Right now, I am using an update query and
updating EACH field to it''s trimmed counterpart. Any ideas? Thanks!

Kevin

这样的东西会起作用 -

Dim Db作为DAO.Database

Dim Rst作为DAO.Recordset

设置Db = CurrentDb()

设置Rst = Db.OpenRecordset( MyTable)

使用Rst

!Field1Name = Trim(!Field1Name)

!Field2Name = Trim(!Field2Name)

---



。关闭

结束

设置Rst = Nothing

设置Db = Nothing

-

PC数据表

您的资源以获取Access,Excel和Word应用程序的帮助
re******@pcdatasheet.com
www.pcdatasheet.com


如果你得不到帮助你需要在新闻组中,我可以帮助你支付非常合理的费用。超过1000名访问用户来找我寻求帮助。

需要一个月历或7天日历吗?需要预约安排?需要

房间预订安排?需要员工的工作安排?联系我!

没有垃圾邮件 <无**** @ earthlink.net>在消息中写道

新闻:o2 ******************************** @ 4ax.com ...
Something like this will work --
Dim Db As DAO.Database
Dim Rst As DAO.Recordset
Set Db = CurrentDb()
Set Rst = Db.OpenRecordset("MyTable")
With Rst
!Field1Name = Trim( !Field1Name)
!Field2Name = Trim( !Field2Name)
---
etc
.Close
End With
Set Rst = Nothing
Set Db = Nothing
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com

If you can''t get the help you need in the newsgroup, I can help you for a
very reasonable fee. Over 1000 Access users have come to me for help.
Need a month calendar or 7 day calendar? Need appointment scheduling? Need
room reservations scheduling? Need employee work scheduling? Contact me!
"No Spam" <no****@earthlink.net> wrote in message
news:o2********************************@4ax.com...
亲爱的Access 2003用户,

有没有办法使用
VBA(首选)一次性修剪表中的所有字段还是查询?现在,我正在使用更新查询和
将EACH字段更新为它的修剪对应物。有任何想法吗?谢谢!

Kevin
Dear fellow Access 2003 Users,

Is there a way to trim all of the fields in a table in one swoop using
VBA (preferred) or a query? Right now, I am using an update query and
updating EACH field to it''s trimmed counterpart. Any ideas? Thanks!

Kevin





PC数据表写道:

PC Datasheet wrote:
这样的东西会起作用 -


不,它不会。你不仅缺少rs.edit和rs.update,它们在编辑记录集数据时也需要

,但即使它确实有效,它也只会给b
做一行最好。它还要求在代码中键入所有字段名

,此时你可能会做得更好,并且在SQL中设置为
update ...。


这是完成工作的一个小功能;


功能修剪()

Dim Db作为数据库

Dim Rs作为记录集

Dim fld As Field


设置Db = CurrentDb()

设置Rs = Db.OpenRecordset(" MyTable")

而不是Rs.EOF

每个fld在Rs.Fields中

使用Rs

。编辑

fld.Value =修剪(fld.Value)

。更新

结束

下一个fld

Rs.MoveNext

Wend

Rs.Close

Set Rs = Nothing

设置Db =没什么

结束功能


PC数据表写道:如果你得不到帮助你需要在新闻组中,我可以帮你收取非常合理的费用。
Something like this will work --
No it won''t. Not only are you missing rs.edit and rs.update which are
required when editing recordset data, but even if it did work it''d only
do one row at best. It also requires that all the fieldnames be typed
into the code, at which point you''re probably better off just doing and
update...set in SQL.

Here''s a little function to get the job done;

Function TrimIt()
Dim Db As Database
Dim Rs As Recordset
Dim fld As Field

Set Db = CurrentDb()
Set Rs = Db.OpenRecordset("MyTable")
While Not Rs.EOF
For Each fld In Rs.Fields
With Rs
.Edit
fld.Value = Trim(fld.Value)
.Update
End With
Next fld
Rs.MoveNext
Wend
Rs.Close
Set Rs = Nothing
Set Db = Nothing
End Function

PC Datasheet wrote: If you can''t get the help you need in the newsgroup, I can help you for a
very reasonable fee.




哦,顺便说一句凯文.. 。免费。



Oh, and by the way Kevin... No charge.


你错过了.Edit和.Update,而你没有循环浏览

的记录。


你的帖子应该给你的大批粉丝留下深刻的印象。


John ... Visio MVP

" PC数据表&QUOT; &LT;无**** @ nospam.spam&GT;在留言中写道

新闻:1i **************** @ newsread2.news.atl.earthli nk.net ...
You are missing the .Edit and the .Update and you are not looping through
the records.

Your post should impress your legions of fans.

John... Visio MVP
"PC Datasheet" <no****@nospam.spam> wrote in message
news:1i****************@newsread2.news.atl.earthli nk.net...
这样的东西会起作用 -
Dim Db As DAO.Database
Dim Rst As DAO.Recordset
Set Db = CurrentDb()
设置Rst = Db.OpenRecordset( MyTable)
使用Rst
!Field1Name = Trim(!Field1Name)
!Field2Name = Trim(!Field2Name)
---
等>。关闭
结束
设置Rst = Nothing
设置Db = Nothing

PC数据表
您的资源以获取Access,Excel和Word应用程序的帮助
Something like this will work --
Dim Db As DAO.Database
Dim Rst As DAO.Recordset
Set Db = CurrentDb()
Set Rst = Db.OpenRecordset("MyTable")
With Rst
!Field1Name = Trim( !Field1Name)
!Field2Name = Trim( !Field2Name)
---
etc
.Close
End With
Set Rst = Nothing
Set Db = Nothing

PC Datasheet
Your Resource For Help With Access, Excel And Word Applications



NOT!


NOT!