Apologies for the cross post...I didn't realise that the forums were connected at all, and thought that this forum was more applicable for the issue. I requested that topic be removed on the other forum, before I posted in this one.
xld, thanks for your input. I think Frosty sorted that out. It didn't make difference, unfortunately.
Frosty, thank you very much. It's at least legible now, if not working! I think the problem is that I've got
ActiveDocument.MailMerge.OpenDataSource _ Name:=SourceDoc, _
and it doesn't like how I've got SourceDoc as an input. This can't be avoided, due to the nature of how the program will be used.
I've got it working like this:
Sub MailMerge()
Dim SourceDoc As String
Dim SelectedItems(1) As String
Dim sConnection As String
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
If .Show <> 0 Then
SelectedItems(1) = SourceDoc
Else
Exit Sub
End If
End With
'your connection string, also more easily separated with line breaks and arguments
sConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"User ID=Admin;" & _
"Data Source=""H:\Jonathon Hunter Hill\AirMaster\AirMaster V 0.9.xlsm"";" & _
"Mode=Read;" & _
"Extended Properties=""HDR=YES;IMEX=1;"";" & _
"Jet OLEDB:System database="""";" & _
"Jet OLEDB:Registry Path="""";" & _
"Jet OLEDB:Engine Type=35;" & _
"Jet OLEDB:"
'using your conection string... with the parameter names and the passed values separated nicely
ActiveDocument.MailMerge.OpenDataSource _
Name:="H:\Jonathon Hunter Hill\AirMaster\AirMaster V 0.9.xlsm", _
ConfirmConversions:=True, _
SQLStatement:="SELECT * FROM `MailMerge`"
'ReadOnly:=False, _
'LinkToSource:=True, _
'AddToRecentFiles:=False, _
'PasswordDocument:="", _
'PasswordTemplate:="", _
'WritePasswordDocument:="", _
'WritePasswordTemplate:="", _
'Revert:=False, _
'Format:=wdOpenFormatAuto, _
'Connection:=sConnection, _
'SQLStatement1:="", _
'SubType:=wdMergeSubTypeAccess
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
End Sub
But it's not acceptable for me to have the source in there, as I've said. So, does anyone have any suggestions of how to get around this? Also, I have commented out most of the ActiveDocument bit because the link to that document makes it over 255 characters, which is apparently unacceptable...
Thanks for your help, chaps.