sending data from word to access

  reddwarfcrew 20:33 25 Mar 07

Hi, I have the code below to send data based on whether optionbutton and
checkboxes were ticked or not to an access database.

Now I can get the code to work fine, but what I wanted to do was have a for
loop that tested each checkbox or optionbutton and then send the data
instead of having to write the code for every checkbox and optionbutton. To
do this, I am holding the fieldname from access in the tag property of the
optionbutton and checkbox.

For some reason, when the code gets to
vRecordSet!xArray(xCount).Tag = "Selected" it fails as it says it
can't find the field in the database. I have put a msgbox in front of this
line to test that it is pulling the tag property correctly and it is.

So what I am expecting in laymens terms is... If the tag proprty holds the
value 'csrName', then the code would become:
vRecordSet!csrName = "Selected"

As I say, if I actually code it with vRecordSet!csrName = "Selected"
it works.

Hope that makes sense.

Any ideas?


Dim xArray()
Dim xCount As Integer
Dim xControl As Control
Dim vConnection As New ADODB.Connection
Dim vRecordSet As New ADODB.Recordset

vConnection.connectionstring = "C:\mi.mdb" &

vRecordSet.Open "miTable", vConnection, adOpenKeyset, adLockOptimistic

For Each xControl In myForm.Controls
If TypeOf xControl Is MSForms.CheckBox Or TypeOf xControl Is
MSForms.OptionButton Then
ReDim Preserve xArray(xCount)
Set xArray(xCount) = xControl
xCount = xCount + 1
End If
Next xControl

For xCount = 0 To UBound(xArray)
If xArray(xCount) = True Then
vRecordSet!xArray(xCount).Tag = "Selected"
vRecordSet!xArray(xCount).Tag = "."
End If
Next xCount

Set vRecordSet = Nothing
Set vConnection = Nothing

  reddwarfcrew 21:18 25 Mar 07


vRecordSet.Fields(xArray(xCount).Tag) = "Selected"

instead of

vRecordSet!xArray(xCount).Tag = "Selected"

if anyone was interested!

This thread is now locked and can not be replied to.

Intel Coffee Lake 8th-gen Core processors release date rumours

1995-2015: How technology has changed the world in 20 years

Framestore’s haunting post-WWII title sequence for new BBC series SS-GB

How to install MacOS Sierra on an older Mac: Get Sierra running on Macs & MacBooks from before 2009