以编程方式更改RecordSource - 风险太大? [英] Programmatically changing RecordSource - too risky?

查看:70
本文介绍了以编程方式更改RecordSource - 风险太大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个弹出窗体,其中包含一个绑定到备注字段的文本框。我已经

警告备忘录字段所以我想知道我是否应该使用此代码。

有没有像这样更改表格的RecordSource的风险?请问

因为备忘录字段有问题吗?


提前致谢。


Private Sub cmdNextNote_Click()

Dim lngNid As Long

如果Me.Dirty那么DoCmd.RunCommand acCmdSaveRecord

lngNid = Nz(DMin(" Note_ID" ,tblNotes"," Entity_ID ="& Me!Entity_ID&

_

" And Note_ID>"& Me!Note_ID) )

如果是lngNid> 0然后调用SetRecordSource(lngNid)

End Sub


Private Sub cmdPreviousNote_Click()

Dim lngNid As Long

如果Me.Dirty然后DoCmd.RunCommand acCmdSaveRecord

lngNid = Nz(DMax(Note_ID,tblNotes,Entity_ID =& Me!Entity_ID&

_

" And Note_ID<"& Me!Note_ID))

如果lngNid> 0然后调用SetRecordSource(lngNid)

End Sub


Private Sub SetRecordSource(lngNid As Long)

Dim strSql As String

Dim db作为DAO.Database

Dim qdfs作为DAO.QueryDefs

Dim qdf作为DAO.QueryDef

如果lngNid> 0然后

''只选择有问题的音符来控制

''拼写检查器的行为:只检查选中的音符,然后检查

完成。

''当RecordSource包含多个音符时,该符号

checker

''继续下一个音符注意,然后在完成之前的下一个 -



''导致表单中出现未选择的注释并导致

'' Form_Unload中的代码失败。

strSql =" SELECT [NoteBrief],[NoteDate],[NoteText],[Note_ID],

Entity_ID" &安培; _

" FROM tblNotes WHERE([Note_ID] ="& lngNid&");"

Else

' '当点击frm0.tglNewNote时,OpenForm方法被称为

'',''acFormAdd''作为数据模式参数,所以我们立即

''到达新纪录;因此我们只需要选择前1个

''记录,以获得可更新的RecordSource

strSql =" SELECT TOP 1 [NoteBrief],[NoteDate], [NoteText],

[Entity_ID]," &安培; _

" [Note_ID] FROM tblNotes;"

结束如果

设置db = CurrentDb

设置qdfs = db.QueryDefs

设置qdf = qdfs(" qryNotesDetail")

qdf.SQL = strSql

Me.RecordSource = qdf。姓名

致电SetNoteHeader

设置qdf =无什么

设置qdfs = Nothing

设置db = Nothing

End Sub

I have a popup form with a textbox that is bound to a memo field. I''ve been
warned about memo fields so I''m wondering if I should use this code. Is
there any risk with changing the form''s RecordSource like this? Am I asking
for trouble doing this with a memo field?

Thanks in advance.

Private Sub cmdNextNote_Click()
Dim lngNid As Long
If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord
lngNid = Nz(DMin("Note_ID", "tblNotes", "Entity_ID = " & Me!Entity_ID &
_
" And Note_ID > " & Me!Note_ID))
If lngNid > 0 Then Call SetRecordSource(lngNid)
End Sub

Private Sub cmdPreviousNote_Click()
Dim lngNid As Long
If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord
lngNid = Nz(DMax("Note_ID", "tblNotes", "Entity_ID = " & Me!Entity_ID &
_
" And Note_ID < " & Me!Note_ID))
If lngNid > 0 Then Call SetRecordSource(lngNid)
End Sub

Private Sub SetRecordSource(lngNid As Long)
Dim strSql As String
Dim db As DAO.Database
Dim qdfs As DAO.QueryDefs
Dim qdf As DAO.QueryDef
If lngNid > 0 Then
''selecting only the note in question controls the behavior of the
''spell checker: only the selected note is checked, then the check
completes.
''When the RecordSource contains more than one note, the spell
checker
''proceeds to the next note, and then the next before completing -
which
''results in an unselected note appearing in the form and causing
''the code in Form_Unload to fail.
strSql = "SELECT [NoteBrief], [NoteDate], [NoteText], [Note_ID],
Entity_ID " & _
"FROM tblNotes WHERE ([Note_ID] = " & lngNid & ");"
Else
''when frm0.tglNewNote is clicked, the OpenForm method is called
''with ''acFormAdd'' as the Data Mode argument, so we immediately
''arrive at a new record; thus we need only select the top 1
''record for the purpose of getting an updatable RecordSource
strSql = "SELECT TOP 1 [NoteBrief], [NoteDate], [NoteText],
[Entity_ID], " & _
"[Note_ID] FROM tblNotes;"
End If
Set db = CurrentDb
Set qdfs = db.QueryDefs
Set qdf = qdfs("qryNotesDetail")
qdf.SQL = strSql
Me.RecordSource = qdf.Name
Call SetNoteHeader
Set qdf = Nothing
Set qdfs = Nothing
Set db = Nothing
End Sub

推荐答案

deko,我不是这个新闻组中经验最丰富或最好的人

回答你的问题,但看起来没有其他人会这样做。我不知道你可能会在备忘录字段中遇到什么,但是我会以
而不是以编程方式更改我的RecordSource而不是创建一个新的

表格/报告每种类别或类型的数据。只要您的字段

名称在表格/查询中相同,我就不会看到问题

会是什么。
deko, I''m not the most experienced or best person on this newsgroup to
answer your question, but it looks like no one else is going to. I
don''t know what you might run into with the memo fields, but I would
rather change my RecordSource programmatically than create a new
form/report for each category or type of data. As long as your field
names are the same in the tables/queries, I don''t see what the problem
would be.


deko写道:
我有一个弹出窗体,其中包含一个绑定到备注字段的文本框。我已被警告过备忘录......
I have a popup form with a textbox that is bound to a memo field. I''ve been
warned about memo fields ....




我被警告过草莓!



I''ve been warned about strawberries!


如果需要所有代码只是为了避免绑定

备忘录字段,那么转储代码并使用绑定的备忘录

字段。


注意:8年前备忘录字段经常被破坏。

今天不要让它定义你的编码习惯。


如果值得使用未绑定的表格或绑定到
a本地表的表格,请为所有字段执行此操作,而不仅仅是备忘录

field。


(david)

" deko" <德** @ nospam.com>在消息中写道

新闻:YO ****************************** @ comcast.com。 ..
If all of that code is required just to avoid a bound
memo field, then dump the code and use a bound memo
field.

Note: memo fields were frequently corrupted 8 years ago.
Don''t let that define your coding practice today.

If it is worth using an unbound form, or a form bound to
a local table, do it for all fields, not just the memo
field.

(david)
"deko" <de**@nospam.com> wrote in message
news:YO******************************@comcast.com. ..
我有一个弹出窗体,其中包含一个绑定到备注字段的文本框。我已经收到有关备忘录字段的警告,所以我想知道是否应该使用此代码。
是否有任何改变表格的RecordSource的风险?我是否在备忘录字段中遇到麻烦?

提前致谢。

Private Sub cmdNextNote_Click()
Dim lngNid As Long
如果Me.Dirty那么DoCmd.RunCommand acCmdSaveRecord
lngNid = Nz(DMin(Note_ID,tblNotes,Entity_ID ="& Me!Entity_ID&
_
⩓ Note_ID>"& Me!Note_ID))
如果是lngNid> 0然后调用SetRecordSource(lngNid)
End Sub

私有子cmdPreviousNote_Click()
Dim lngNid As Long
如果Me.Dirty然后DoCmd.RunCommand acCmdSaveRecord
lngNid = Nz(DMax(Note_ID,tblNotes,Entity_ID ="& Me!Entity_ID&
_
和Note_ID<"& Me !Note_ID))
如果是lngNid> 0然后调用SetRecordSource(lngNid)
结束Sub

私有子SetRecordSource(lngNid为长)
Dim strSql As String
Dim db作为DAO.Database
Dim qdfs作为DAO.QueryDefs
Dim qdf作为DAO.QueryDef
如果lngNid> 0然后
''只选择有问题的音符来控制
''拼写检查器的行为:只选中所选的音符,然后检查
完成。
''当RecordSource包含多个音符时,拼写
检查器
''进入下一个音符,然后在下一个音符完成之前 -
'
''导致未选中注意出现在窗体中并导致Form_Unload中的代码失败。
strSql =" SELECT [NoteBrief],[NoteDate],[NoteText],[Note_ID],
Entity_ID " &安培; _
" FROM tblNotes WHERE([Note_ID] ="& lngNid&");"
Else
''当点击frm0.tglNewNote时,OpenForm方法是将'acFormAdd'称为
''作为数据模式参数,因此我们立即达到新记录;因此我们只需要选择前1个记录来获取可更新的RecordSource
strSql =" SELECT TOP 1 [NoteBrief],[NoteDate],[NoteText],
[Entity_ID], &安培; _
" [Note_ID] FROM tblNotes;"
结束如果
设置db = CurrentDb
设置qdfs = db.QueryDefs
设置qdf = qdfs(" qryNotesDetail")
qdf.SQL = strSql
Me.RecordSource = qdf.Name
调用SetNoteHeader
设置qdf = Nothing
设置qdfs = Nothing
设置db = Nothing
End Sub
I have a popup form with a textbox that is bound to a memo field. I''ve
been warned about memo fields so I''m wondering if I should use this code.
Is there any risk with changing the form''s RecordSource like this? Am I
asking for trouble doing this with a memo field?

Thanks in advance.

Private Sub cmdNextNote_Click()
Dim lngNid As Long
If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord
lngNid = Nz(DMin("Note_ID", "tblNotes", "Entity_ID = " & Me!Entity_ID &
_
" And Note_ID > " & Me!Note_ID))
If lngNid > 0 Then Call SetRecordSource(lngNid)
End Sub

Private Sub cmdPreviousNote_Click()
Dim lngNid As Long
If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord
lngNid = Nz(DMax("Note_ID", "tblNotes", "Entity_ID = " & Me!Entity_ID &
_
" And Note_ID < " & Me!Note_ID))
If lngNid > 0 Then Call SetRecordSource(lngNid)
End Sub

Private Sub SetRecordSource(lngNid As Long)
Dim strSql As String
Dim db As DAO.Database
Dim qdfs As DAO.QueryDefs
Dim qdf As DAO.QueryDef
If lngNid > 0 Then
''selecting only the note in question controls the behavior of the
''spell checker: only the selected note is checked, then the check
completes.
''When the RecordSource contains more than one note, the spell
checker
''proceeds to the next note, and then the next before completing -
which
''results in an unselected note appearing in the form and causing
''the code in Form_Unload to fail.
strSql = "SELECT [NoteBrief], [NoteDate], [NoteText], [Note_ID],
Entity_ID " & _
"FROM tblNotes WHERE ([Note_ID] = " & lngNid & ");"
Else
''when frm0.tglNewNote is clicked, the OpenForm method is called
''with ''acFormAdd'' as the Data Mode argument, so we immediately
''arrive at a new record; thus we need only select the top 1
''record for the purpose of getting an updatable RecordSource
strSql = "SELECT TOP 1 [NoteBrief], [NoteDate], [NoteText],
[Entity_ID], " & _
"[Note_ID] FROM tblNotes;"
End If
Set db = CurrentDb
Set qdfs = db.QueryDefs
Set qdf = qdfs("qryNotesDetail")
qdf.SQL = strSql
Me.RecordSource = qdf.Name
Call SetNoteHeader
Set qdf = Nothing
Set qdfs = Nothing
Set db = Nothing
End Sub



这篇关于以编程方式更改RecordSource - 风险太大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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