Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Performing a Merge Query

Status
Not open for further replies.

tag923

Technical User
Oct 1, 2002
1
US
I will admit I'm not a VB programmer, so I need desperately need help. I'm trying to select a data record from a source table in order to copy the information into a form. I'm attempting to prompt the user to enter the unique record identifier, in this case it's the file number (named SLO) so that the SLO and the CaseName appears on the form.

I recorded a macro and attempted to edit it to do exactly what I want it to do. However, it bombs out after I enter the SLO. PLEASE HELP!!!! THANKS!

Dim varcasenumber As Integer
varcasenumber = InputBox("Enter SLO#")
(I get the error message at this point)
ActiveDocument.MailMerge.DataSource.QueryString = _
"SELECT CaseName FROM H:\Cases\Active Case Data for Word.doc WHERE SLO = '[varcasenumber]'"
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
Selection.Fields.Locked = True
Selection.HomeKey Unit:=wdStory
ActiveDocument.Protect Password:="", NoReset:=False, Type:= _
wdAllowOnlyFormFields
End Sub
 
InputBox returns a string even when the user enters a number. You can try this:
varcasenumber = CInt(InputBox("Enter SLO#"))
but if the user enters something that can't be converted to an integer, it will crash.

Take a look in your help files about using IsNumber before attempting to convert the string and causing the crash.

I don't know much about MailMerge Data Sources so I ask you whether the field you are using is string or integer? If string, your variable varcasenumber should be a String also and your problem solved. . . . hopefully.

Hope it helps

Roger
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top