Question : Access VBA Help for Form Movement

Hello EE:
I've pasted a VBA sub and the Debug.Print results below.

Using Access 2007 my intent is to create a recordset that causes the user's form contents to change and then run a macro pertinent to that form.  Looking at the debug.print results the module is going through the recordset, but the form is is not.

Thanks,
LVBarnes
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
Private Sub MassApprove_Click()
On Error GoTo ErrorHandler

    Dim strControl As String
    Dim rst As New ADODB.Recordset
    Dim rcd As String
    
    strControl = "Forms!txtRecordKey"

    strSQL = "SELECT tblImportClaims.FileID&tblImportClaims.FileTabName&tblImportClaims.DefaultCustNbr&tblImportClaims.ClaimTypeDesc AS RecordKey" & _
             ", tblImportClaims.FileID, tblImportClaims.FilePath, tblImportClaims.FileName, tblImportClaims.FileTabName" & _
             ", tblImportClaims.FileDate, tblImportClaims.FileSize, tblImportClaims.DefaultCustNbr, tblImportClaims.Analyst" & _
             ", tblImportClaims.ClaimTypeDesc, tblImportClaimFilesLocal.MassSchemaApprv " & _
             "FROM tblImportClaims INNER JOIN tblImportClaimFilesLocal " & _
             "ON (tblImportClaims.DefaultCustNbr = tblImportClaimFilesLocal.DefaultCustNbr) " & _
             "AND (tblImportClaims.ClaimTypeDesc = tblImportClaimFilesLocal.ClaimTypeDesc) " & _
             "AND (tblImportClaims.FileSize = tblImportClaimFilesLocal.FileSize) " & _
             "AND (tblImportClaims.FileDate = tblImportClaimFilesLocal.FileDate) " & _
             "AND (tblImportClaims.FileName = tblImportClaimFilesLocal.FileName) " & _
             "AND (tblImportClaims.FilePath = tblImportClaimFilesLocal.FilePath) " & _
             "WHERE tblImportClaimFilesLocal.MassSchemaApprv=-1;"

Debug.Print "strSQL: " & strSQL

    With rst
        .Open strSQL, CurrentProject.Connection, adOpenStatic, adLockReadOnly
    
    Do While Not rst.EOF

        Me.Recordset.FindFirst strControl = rst(0)
        
Debug.Print "Current Form Record " & Forms!frmImportSchemaCheck.txtFileID & "_" & Forms!frmImportSchemaCheck.FileName & Forms!frmImportSchemaCheck.FileTabName
Debug.Print "Current recordset record: " & rst(0)
        
        DoCmd.RunMacro "mcrTransfertoWorking" 'This macro runs from values in the current form.  Form needs to change for each macro.
        
        rst.MoveNext
    Loop
    rst.Close
    End With

Exit Sub

ErrorHandler:
    MsgBox "Error: " & Err.Number & vbCrLf & Err.Description

End Sub

**** Immediate Window ****
Note how the form debug.print values are not updating.  This causes the macro to run twice, but on the same form.

strSQL: SELECT tblImportClaims.FileID&tblImportClaims.FileTabName&tblImportClaims.DefaultCustNbr&tblImportClaims.ClaimTypeDesc AS RecordKey, tblImportClaims.FileID, tblImportClaims.FilePath, tblImportClaims.FileName, tblImportClaims.FileTabName, tblImportClaims.FileDate, tblImportClaims.FileSize, tblImportClaims.DefaultCustNbr, tblImportClaims.Analyst, tblImportClaims.ClaimTypeDesc, tblImportClaimFilesLocal.MassSchemaApprv FROM tblImportClaims INNER JOIN tblImportClaimFilesLocal ON (tblImportClaims.DefaultCustNbr = tblImportClaimFilesLocal.DefaultCustNbr) AND (tblImportClaims.ClaimTypeDesc = tblImportClaimFilesLocal.ClaimTypeDesc) AND (tblImportClaims.FileSize = tblImportClaimFilesLocal.FileSize) AND (tblImportClaims.FileDate = tblImportClaimFilesLocal.FileDate) AND (tblImportClaims.FileName = tblImportClaimFilesLocal.FileName) AND (tblImportClaims.FilePath = tblImportClaimFilesLocal.FilePath) WHERE tblImportClaimFilesLocal.MassSchemaApprv=-1;
Current Form Record 14822_092509 Paper Dispute 239630 BSCC ClevelandUPL_1massj.csvNoTab
Current recordset record: 14822NoTab88888888RST
Current Form Record 14822_092509 Paper Dispute 239630 BSCC ClevelandUPL_1massj.csvNoTab
Current recordset record: 14823NoTab88888888RST

Answer : Access VBA Help for Form Movement


use the name of the field. not the name of the control on this line

if [FieldName] is Number use this
Me.Recordset.FindFirst "[fieldName] = " & rst(0)


if [FieldName] is Text use this
Me.Recordset.FindFirst "[fieldName] = '" & rst(0) &"'"
Random Solutions  
 
programming4us programming4us