sending data from word to access

  reddwarfcrew 20:33 25 Mar 2007
Locked

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?


Thanks.


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" &
"Provider=Microsoft.Jet.OLEDB.4.0;"
vConnection.Open


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


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"
Else
vRecordSet!xArray(xCount).Tag = "."
End If
Next xCount

vRecordSet.Update
vRecordSet.Close
vConnection.Close
Set vRecordSet = Nothing
Set vConnection = Nothing

  reddwarfcrew 21:18 25 Mar 2007

needed:

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.

Elsewhere on IDG sites

Alienware 17 R4 2017 review

Illustrator Sylvain Tegroeg created thousands of intricate line drawings for the mobile game…

Best iPad buying guide 2017

Comment télécharger une application indisponible en France ?