Problem:
I want a button in Word to update access table with a value set by a drop-down field in the same Word document. The drop down field is to set the Status_ID field in the Access table. It has an integer value (1-9) that corresponds to text drop-down selectons for things like 'cancelled', 'reschedule' etc.
Here is the basis of my code:
When I test this code it works, but the SQL is static (I also want to include a where clause that selects by Session_ID, located in table cell value on the word document) and want the recordset loop to update based on the drop-down field.
When I change it to:
I get runtime error 5941. Do I need to activate the word document, despite having it already open? What am I missing?
I want a button in Word to update access table with a value set by a drop-down field in the same Word document. The drop down field is to set the Status_ID field in the Access table. It has an integer value (1-9) that corresponds to text drop-down selectons for things like 'cancelled', 'reschedule' etc.
Here is the basis of my code:
Code:
Private Sub CommandButton1_Click()
Dim vConnection As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strCnxn As String
Dim strSQL As String
strCnxn = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"C:\session\myconnectionstring.accdb;Persist Security Info=False;"
Set vConnection = New ADODB.Connection
vConnection.Open strCnxn
strSQL = "SELECT * FROM [Session] WHERE Session_ID = 101;"
Set rs = New ADODB.Recordset
rs.Open strSQL, vConnection, adOpenStatic, adLockOptimistic
With rs
rs.MoveFirst
Do Until rs.EOF
rs!Status_ID = 9
rs.Update
rs.MoveNext
Loop
End With
End Sub
When I test this code it works, but the SQL is static (I also want to include a where clause that selects by Session_ID, located in table cell value on the word document) and want the recordset loop to update based on the drop-down field.
When I change it to:
Code:
rs!Status_ID = ActiveDocument.FormFields("Session_Status").DropDown.Value
I get runtime error 5941. Do I need to activate the word document, despite having it already open? What am I missing?