If you want to provide db, follow instructions at bottom of my post.
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.
Here is what I see: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
I would guess you do not have the following two lines at the top of EVERY module:
You have declared "intNo" as Long but use "i", which is not declared. (see the red highlights in the code above)Code:Option Compare Database Option Explicit
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.
See: http://access.mvps.org/access/tencommandments.htmCode:rst.Fields("[Date of Test]") = Me.Controls("Textbox" & i)
and for good measure, see: http://access.mvps.org/access/lookupfields.htm
edit: I was delayed in posting due to work![]()
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.
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