Oops, I tried to simplify and I think I simplified the problem out of the
code. I think the problem is with AddCompany in the following code:
Private Sub Combo55_AfterUpdate()
On Error GoTo Err_Combo55_AfterUpdate
Dim rs As Object
If IsNull(Combo55) = False Then
If Combo55 <> "Town Committee" Then
Set rs = Me.Recordset.Clone
rs.FindFirst "[Company Sort] = '" & Me![Combo55] & "'"
Me.Bookmark = rs.Bookmark
Call AddCompany
Else
DoCmd.GoToRecord , , acFirst
Do
If Site = True Then Call AddContact
DoCmd.GoToRecord , , acNext
Loop
End If
End If
Me.Combo55 = ""
Exit_Combo55_AfterUpdate:
Exit Sub
Err_Combo55_AfterUpdate:
Me.Combo55 = ""
Resume Exit_Combo55_AfterUpdate
End Sub
Here's the AddCompany code:
Private Sub AddCompany()
On Error GoTo Err_AddCompany
Dim stDocName As String
stDocName = "rptGLResultTable"
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Integer
Set db = CurrentDb
Set rs = db.OpenRecordset("tblAddressMatch", dbOpenDynaset)
For i = 1 To Me!NumOfLabels
rs.AddNew
rs!MatchComID = Me![MatchComID]
rs![COMPANIES TABLE_Company Name] = Me![COMPANIES TABLE_Company
Name]
rs![Company Sort] = Me![Company Sort]
rs!Address1 = Me!Address1
rs!Address2 = Me!Address2
rs!City = Me!City
rs!State = Me!State
rs!Zip = Me!Zip
rs.Update
Next i
Me!NumOfLabels = 1
LABELS_Subform.Requery
Exit_AddCompany:
Exit Sub
Err_AddCompany:
MsgBox Err.Description
Resume Exit_AddCompany
End Sub
Combo55 is on a form that merges with Word to create mailing labels. A
company name is selected in Combo55 and the contact info is added to a
subform. Mailing labels are created for the companies listed in the
subform
using the OnClick procedure of a command button. If Town Committee is
selected, all town members are listed with their contact info and a label
is
made for each member. This is the only selection when multiple contacts
are
listed with one selection on Combo55 (that is why it has special code).
Otherwise, the company that is selected in Combo55 will be listed in a
subform and a mailing label will be created (after clicking the command
button). The problem is, when there is an apostrophe in the company's
name
that is selected in Combo55, the subform does not populate with that
company.
If there is no apostrophe in Combo55, everything works fine. But, I'm new
to Access and have inherited this database, so any help is appreciated.
Thanks.
KAW said:
I inherited a database and figured out that the following code will not
work
if there is an apostrophe in the record. Any suggestions?
Private Sub Combo55_AfterUpdate()
On Error GoTo Err_Combo55_AfterUpdate
Dim rs As Object
If IsNull(Combo55) = False Then
DoCmd.GoToRecord , , acFirst
Do
If Site = True Then Call AddContact
DoCmd.GoToRecord , , acNext
Loop
End If
Me.Combo55 = ""
Exit_Combo55_AfterUpdate:
Exit Sub
Err_Combo55_AfterUpdate:
Me.Combo55 = ""
Resume Exit_Combo55_AfterUpdate
End Sub
Thanks!