如何让Recordset#2处于与相似记录集#1相同的位置

时间:2015-05-24 07:33:19

标签: vba ms-access access-vba recordset

我正在使用2个记录集:#1和#2。记录集#1是表单记录集,它不是DataUpdatable,因为它的源是具有不可编辑字段的查询。记录集#2是DataUpdatable,因为它的源是一个表。记录集#2表是记录集#1表源。

每次保存表单的控件值时,我都会将记录集状态更改为“添加/编辑”,将每个值粘贴到其各自的记录集字段中并添加记录集。问题是我必须在记录集#2中这样做,因为#1不可编辑。我需要的是在粘贴控件值之前将记录集#2位置移动到相同的#1位置。我正在尝试在记录集#2中使用记录集#1书签,因为它们具有相同的表结构,字段总数等...但它表示书签无效。

两个记录集的顺序相同,两个SQL源都有“ORDER BY”子句。对于AddNew模式,没有问题,因为记录集位置是新的,不需要找到它。问题出在EditInProgress模式,因为我必须匹配两个位置,这样我就可以将表单记录集#1字段的控制值更新为等效的记录集#2字段。

提前感谢。

嗨,AVG。这是加密/解密代码:

Public Function EncriptarDecriptarTexto(textoNormal As Variant) As Variant
    On Error GoTo ErroGeral
    Dim posicaoLetraEncript As Integer
    Dim valorLetraEncript As Integer
    Dim tamanhoTextoNormal As Integer
    Dim tamanhoTextoEncript As Integer
    Dim textoEncript As String
    Dim i As Integer

    If ((textoNormal & "") = "") Then
        GoTo ErroGeral
    End If

    tamanhoTextoNormal = Len(textoNormal)
    tamanhoTextoEncript = Len(textoEncript)
    posicaoLetraEncript = 0
    textoEncript = "Any text you want"

    For i = 1 To tamanhoTextoNormal
        posicaoLetraEncript = posicaoLetraEncript + 1

        If posicaoLetraEncript > tamanhoTextoEncript Then
            posicaoLetraEncript = 1
        End If

        valorLetraEncript = Asc(Mid(textoEncript, posicaoLetraEncript, 1))
        Mid(textoNormal, i, 1) = Chr(Asc(Mid(textoNormal, i, 1)) Xor valorLetraEncript)
    Next i

    EncriptarDecriptarTexto = textoNormal

Sair:
    Exit Function
ErroGeral:
    EncriptarDecriptarTexto = Null
    GoTo Sair
End Function

关于表更新:我现在通过INSERT / UPDATE语句进行更新。

1 个答案:

答案 0 :(得分:1)

这听起来像设计糟糕的设计。也就是说,只需使用更新语句,而不是打开第二个记录集并尝试与表单的记录源同步。 Update <YourTable> SET <field1> = <NewValue1>, <field2> = <NewValue2> WHERE <PK>=<CurrentRecordPK>

相关问题