Thor My
Thor My

Reputation: 299

How to Let Recordset #2 in the Same Position as the Similar Recordset#1

I'm working with 2 recordsets: #1 and #2. recordset #1 is the form recordset, which is NOT DataUpdatable because its source is a query with non editable fields. recordset #2 is DataUpdatable because its source is a table. recordset #2 table is the recordset #1 table source.

every time I save the form's controls values, I change the recordset status to Add/Edit, paste each value in its respective recordset field and upadte the recordset. the problem is that I have to do it in the recordset #2 because #1 is not editable. what I need is to move recordset #2 position to the same #1 position before I paste the control values. I'm trying to use the recordset #1 bookmark in recordset #2, since they have the same table structure, total of fields, etc... but it says that the bookmark is not valid.

both recordsets are in the same order, both SQL sources have "ORDER BY" clause. for AddNew mode there's no problem because the recordset position is a new one, don't need to find it. the problem is for EditInProgress mode because I have to match both positions so I can update the form's control values addressed to recordset #1 fields into the equivalent recordset #2 fields.

thanks in advance.

hi, AVG. this is the encrypt/decrypt code:

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

about the table update: I'm now updating through INSERT/UPDATE statements.

Upvotes: 0

Views: 136

Answers (1)

AVG
AVG

Reputation: 1462

This sounds like poor design to start with. That said, instead of opening a second recordset and trying to synchronize with the form's recordsource, simply use an update statement. Update <YourTable> SET <field1> = <NewValue1>, <field2> = <NewValue2> WHERE <PK>=<CurrentRecordPK>

Upvotes: 1

Related Questions