shelley2000
Programmer
Hi, Help, and Thanks
I am using Word 2003 and Access 2003. For reasons out my control, I have to use Word Forms vice Access Forms. I will be sending a Word Form to my department employees to fill out. the number of fields they need to fill out is variable. I want to check each of the form fields to see if the they have data or not. My dropdown form field check is erroring with ...
"5825; Object has been deleted"
For example, I have a Word table to select up to 15 Projects. each of the 15 rows in Word TAble has 1) a drop down to allow users to select the projects they have worked on. The drop down list is populated from Access Project name table and I was unsuccesful on getting word dropdown to take a default. The second column is the number of years.
Users will just select the number of projects the other drop downs will be empty. I need to check the drop down to see if it is empty and I don't know how to do it without getting error.
Projects: (Select up to 15 projects)
Count Project Name Years
1. <drop down list> <text numeric>
...
15. <drop down list> <text numeric>
Here are the things I have tried that crash:
If IsNull(ActiveDocument.FormFields(FieldName1))
If Len(Nz(ActiveDocument.FormFields(FieldName1).Result, "") & vbNullString) > 0 Then
Here is the code:
Dim rstEmployeeProject As New ADODB.Recordset
Dim rstProjects As New ADODB.Recordset
Dim ProjectNameIn As String
Dim prjctid As Integer
rstEmployeeProject.Open "tblEmployeeProject", cnn, adOpenKeyset, adLockOptimistic
strSQL = "select ProjectID, ProjectNameShort from tblProjects order by ProjectNameShort"
rstProjects.Open strSQL, cnn, dOpenKeyset, adLockOptimistic, adCmdText
With rstEmployeeProject
For Counter = 1 To 15 ' There are 15 Projects allowed in form
FieldName1 = "fldSklPExpNm" & Counter
FieldName2 = "fldSklPExpNm" & Counter & "Yr"
If IsNull(ActiveDocument.FormFields(FieldName1)) Then
MsgBox "null field"
Counter = 16
Else
rstProjects.MoveFirst
If Len(Nz(ActiveDocument.FormFields(FieldName1).Result, "") & vbNullString) > 0 Then
ProjectNameIn = ActiveDocument.FormFields(FieldName1).Result
recCount = rstProjects.RecordCount
'prjctid = DLookup("[ProjectID]", "tblProjects", "[ProjectNameShort]='QL'")
rstProjects.Find "ProjectNameShort='" & ProjectNameIn & "'"
If rstProjects.EOF Then
rstProjects.MoveFirst
MsgBox "ProjectNameShort =" & ProjectNameIn & "was not found. Using 26: other Project name. please log problem."
rstProjects.Find "ProjectNameShort='Other'"
If rstProjects.EOF Then
MsgBox "ProjectNameShort = 'Other' was not found. No project was added. Please log problem."
Else
prjctid = rstProjects.Fields(0)
End If
Else
prjctid = rstProjects.Fields(0)
End If
rstEmployeeProject.AddNew
rstEmployeeProject!employeeID = rstEmployees!employeeID
rstEmployeeProject!projectID = prjctid
rstEmployeeProject!Years = ActiveDocument.FormFields(FieldName2).Result
rstEmployeeProject.Update
Else '****Either an empty record was found or the last record was processed ****"
Counter = 16
End If
End If
Next
rstProjects.Close
rstEmployeeProject.Close
End With '**** end with rstEmployeeProject ****'
Help: how do I check the dropdown formfields to see if they have been updated or not with getting error.
Thanks,
shelley
I am using Word 2003 and Access 2003. For reasons out my control, I have to use Word Forms vice Access Forms. I will be sending a Word Form to my department employees to fill out. the number of fields they need to fill out is variable. I want to check each of the form fields to see if the they have data or not. My dropdown form field check is erroring with ...
"5825; Object has been deleted"
For example, I have a Word table to select up to 15 Projects. each of the 15 rows in Word TAble has 1) a drop down to allow users to select the projects they have worked on. The drop down list is populated from Access Project name table and I was unsuccesful on getting word dropdown to take a default. The second column is the number of years.
Users will just select the number of projects the other drop downs will be empty. I need to check the drop down to see if it is empty and I don't know how to do it without getting error.
Projects: (Select up to 15 projects)
Count Project Name Years
1. <drop down list> <text numeric>
...
15. <drop down list> <text numeric>
Here are the things I have tried that crash:
If IsNull(ActiveDocument.FormFields(FieldName1))
If Len(Nz(ActiveDocument.FormFields(FieldName1).Result, "") & vbNullString) > 0 Then
Here is the code:
Dim rstEmployeeProject As New ADODB.Recordset
Dim rstProjects As New ADODB.Recordset
Dim ProjectNameIn As String
Dim prjctid As Integer
rstEmployeeProject.Open "tblEmployeeProject", cnn, adOpenKeyset, adLockOptimistic
strSQL = "select ProjectID, ProjectNameShort from tblProjects order by ProjectNameShort"
rstProjects.Open strSQL, cnn, dOpenKeyset, adLockOptimistic, adCmdText
With rstEmployeeProject
For Counter = 1 To 15 ' There are 15 Projects allowed in form
FieldName1 = "fldSklPExpNm" & Counter
FieldName2 = "fldSklPExpNm" & Counter & "Yr"
If IsNull(ActiveDocument.FormFields(FieldName1)) Then
MsgBox "null field"
Counter = 16
Else
rstProjects.MoveFirst
If Len(Nz(ActiveDocument.FormFields(FieldName1).Result, "") & vbNullString) > 0 Then
ProjectNameIn = ActiveDocument.FormFields(FieldName1).Result
recCount = rstProjects.RecordCount
'prjctid = DLookup("[ProjectID]", "tblProjects", "[ProjectNameShort]='QL'")
rstProjects.Find "ProjectNameShort='" & ProjectNameIn & "'"
If rstProjects.EOF Then
rstProjects.MoveFirst
MsgBox "ProjectNameShort =" & ProjectNameIn & "was not found. Using 26: other Project name. please log problem."
rstProjects.Find "ProjectNameShort='Other'"
If rstProjects.EOF Then
MsgBox "ProjectNameShort = 'Other' was not found. No project was added. Please log problem."
Else
prjctid = rstProjects.Fields(0)
End If
Else
prjctid = rstProjects.Fields(0)
End If
rstEmployeeProject.AddNew
rstEmployeeProject!employeeID = rstEmployees!employeeID
rstEmployeeProject!projectID = prjctid
rstEmployeeProject!Years = ActiveDocument.FormFields(FieldName2).Result
rstEmployeeProject.Update
Else '****Either an empty record was found or the last record was processed ****"
Counter = 16
End If
End If
Next
rstProjects.Close
rstEmployeeProject.Close
End With '**** end with rstEmployeeProject ****'
Help: how do I check the dropdown formfields to see if they have been updated or not with getting error.
Thanks,
shelley