Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771

    If you want to provide db, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  2. #17
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Code:
    Private Sub Command193_Click()
       Dim db As DAO.Database
       Dim rst As DAO.Recordset
       Dim intNo As Long
    
       Set db = CurrentDb
       Set rst = db.OpenRecordset("Radio Testing")
    
    '   Do
          For i = 0 To 158 Step 2
             rst.AddNew
             rst.Fields("Date of Test") = Me.Controls("Textbox" & i)
             rst.Fields("Facility") = Me.Controls("Label" & i)
             rst.Update
             '         rst.NextRecordset
    
          Next
    '   Loop
    
    End Sub
    Here is what I see:
    I would guess you do not have the following two lines at the top of EVERY module:
    Code:
    Option Compare Database
    Option Explicit
    You have declared "intNo" as Long but use "i", which is not declared. (see the red highlights in the code above)
    As noted before, you can remove "Do", "rst.NextRecord" (which should have been rst.MoveNext for a recordset) and "Loop".

    The reason you are getting an error is that you have spaces in object names. This is a very bad thing to do. It causes major headaches.
    You need to put brackets around any names that have spaces.
    Code:
             rst.Fields("[Date of Test]") = Me.Controls("Textbox" & i)
    See: http://access.mvps.org/access/tencommandments.htm
    and for good measure, see: http://access.mvps.org/access/lookupfields.htm

    edit: I was delayed in posting due to work

  3. #18
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Spaces and special characters should be avoided because they often cause issue and need the []. It's just best to avoid.

    However, this isn't one of those cases and something else is wrong.

    rst.Fields("Date of Test") will work - I tested

    rst!DateOfTest will work

    rst![Date of Test] will work

    rst!Date of Test will not work
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #19
    g4tv4life is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    50

    D'oh

    Do you ever code something then go back with a fresh brain and say what in the hell was I doing? well I had that Epiphany today.

    The reason it wasn't working is because the "Date of Testing" field is a date/time field and I was trying to stuff a "Yes/No" value into it.

    Added a new text field for the yes/no value and code to insert the date and bingo, all works great. Sorry for wasting your time June and Drex.

    Here's my final code for all who wish to view my stupidity.

    Code:
    Private Sub Command193_Click()
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Set db = CurrentDb
    Set rst = db.OpenRecordset("Radio Testing")
    For i = 0 To 158 Step 2
    rst.AddNew
    rst.Fields("[Date of Testing]") = [Text300].Value
    rst.Fields("Response") = Me.Controls("text" & i).Value
    rst.Fields("Facility") = Me.Controls("label" & i).Caption
    rst.Update
    Next
    End Sub

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Form to Create Multiple Records
    By panza1370 in forum Forms
    Replies: 1
    Last Post: 06-11-2012, 02:48 PM
  2. Replies: 11
    Last Post: 09-27-2011, 07:19 AM
  3. Create multiple records with 1 form?
    By bergjes in forum Forms
    Replies: 4
    Last Post: 04-14-2010, 06:16 AM
  4. Trying to create multiple records from a form
    By ed_hollywood in forum Forms
    Replies: 4
    Last Post: 04-02-2010, 10:57 PM
  5. Replies: 3
    Last Post: 06-01-2009, 01:41 PM

Tags for this Thread

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