Results 1 to 12 of 12
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Wrong syntax on DOA.Recordset field update

    Click image for larger version. 

Name:	000.jpg 
Views:	24 
Size:	55.3 KB 
ID:	45949



    Since I know, as with the failed statement, that "Mov1" is a valid field in the current DAO Recordset, I assume the syntax is wrong? The compiler only demanded the brackets. I verified in Debug that the current value of "I" is in fact one (1).

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Have never seen nor would use Me("something"). If not Me.Something then Me.Controls("Something")
    Perhaps the form collection is the collection being referred to. Could try the bracketed syntax above or replace with a valid value as a test.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Could try the bracketed syntax above or replace with a valid value as a test.
    That was the first thing I tried. I.e., !["Mov" & I] = "" Also, I first coded the source of the assignment Me.Controls("tbMov" & I) like I would normally do but dropped the ".Control" only after trying a few other things out of desperation.

  4. #4
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Try
    Code:
    .Fields("Mov" & I) = Me.Controls("tbMov" & I)

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Then as always, must verify that values and concatenations are what you expect. I get the impression that this happens even on the first pass which is why I didn't mention that the collection is zero based if it is for a recordset fields or form controls. So it's more than likely that at least Mov1 would work. I guess I'd be debug.printing either
    rs!fields("Mov" & I).Name (or for the form controls collection).
    Not sure which because your post suggests that there is a With block above and I'm assuming it is for the recordset. Do you mind if I ask why you post the absolute minimum amount of code when you need help? It begs too many questions and assumptions - at least on my part.
    Last edited by Micron; 08-11-2021 at 01:50 PM. Reason: spelin and gramur
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    My access at least wont digest !["Mov" & I]
    It doesn't complain about .Fields("Mov" & I) though.

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Yes, perfect. Access simply needed to recognize my referenced to members of the Fields collection.
    Bill

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    It doesn't complain about .Fields("Mov" & I) though.
    It will work IF the With is

    With rs.Fields but not if it is With rs

    as in
    Code:
    With rs.Fields
       Debug.Print !sysnum
    End With
    which works. Too bad what the With was about wasn't evident.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Code:
    Set rsWorks = DBEngine(0)(0).OpenRecordset("QWorks")
    
    With rsWorks
    
        .AddNew
        !Title = WorksTitle
        !CatSystem = CatSys
        !CatSystemVal = CatSysVal
        !CompID = CompID
        !OrchID = OrchID
        !CondID = CondID
        !GenreID = GenreID
        !SoloID = SoloID
        !VolID = lngVolID
        For I = 1 To 16
            .Fields("Mov" & CStr(I)) = Me.Controls("tbMov" & CStr(I))
            .Fields("Mov" & CStr(I) & "t") = Me.Controls("t" & CStr(I))
        Next I
        .Update
    End With
    
    rsWorks.Close
    Set rsWorks = Nothing

  10. #10
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by Micron View Post
    It will work IF the With is

    With rs.Fields but not if it is With rs

    as in
    Code:
    With rs.Fields
       Debug.Print !sysnum
    End With
    which works. Too bad what the With was about wasn't evident.

    In my testing I found it was the !["..."] notation it barked at. To be specific it's the string within the square brackets. I've used ![ControlName] without issue

    Code:
    Private Sub Command6_Click()
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim I As Integer
        
        Set db = CurrentDb
        Set rs = db.OpenRecordset("Table1")
        
        With rs
            .AddNew
            
            'For I = 1 To 3
                '.Fields("Mov" & I) = Me.Controls("tbMov" & I)
            'Next I
            
            ![Mov1] = Me.Controls("tbMov1") '<---- This works
            
            !["Mov1"] = Me.Controls("tbMov1") '<---- This doesn't work
    
            
            .Update
            .Close
        End With
        
        
        Set rs = Nothing
        Set db = Nothing
    End Sub

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    !["Mov1"] = Me.Controls("tbMov1") '<---- This doesn't work

    because of the quotes inside the brackets? [ ] defines the field name so [field1], not ["field1"].
    Either [Mov1] or ("Mov1") but not ["Mov1"].

    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Yep, that's what I've found.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. DOA Recordset RecordCount returns wrong value
    By GraeagleBill in forum Programming
    Replies: 2
    Last Post: 06-12-2021, 11:54 AM
  2. Replies: 5
    Last Post: 09-16-2018, 01:18 PM
  3. DAO recordset field reference syntax
    By GraeagleBill in forum Programming
    Replies: 3
    Last Post: 04-23-2016, 06:02 PM
  4. Date Syntax in vba is wrong ?
    By burrina in forum Forms
    Replies: 3
    Last Post: 02-20-2013, 12:34 AM
  5. Wrong reference with .fields in DAO recordset
    By ddd in forum Programming
    Replies: 1
    Last Post: 12-08-2009, 05:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums