Skip to main content

Dialog Box to Map Fields

I'm very new to scripting, and I'm struggling a bit with understanding how to properly use dialog boxes. What I'd like to do is pop up a dialog box to have the user map the fields in their client's data to a standard naming convention, so that I can run a pre-designed analysis. I've been successful at building the script to handle the analysis part by using the macro recorder and the history, but I'm stumped on the dialog box part. 
 
Could anyone point me to some guidance or help me out on this? I've got a copy of Mueller's Mastering IdeaScript but it doesn't seem to cover this. 
 
Thanks!
Leslie

Brian Element Thu, 02/01/2018 - 05:00

In reply to by mllestecchino

Hi there,

I reworked your Mapping function to work with the open file.  It will give an error if no file is open.

 


Function Mapping()

	fileName = Client.CurrentDatabase.Name
	Set source=client.opendatabase(fileName)
	Set table=source.tabledef
	fields=table.count
	ReDim fieldlist1$(fields)
	j=0
	k=0
	
	For i = 1 To Fields
		Set field=table.getfieldat(i)
		If field.IsCharacter Then
			fieldlist1$(j)=field.name
			j=j+1
		End If
	Next i
	If j = 0 Then 
		MsgBox "There are no character fields in this file"
	End If

mapping_start:
	button = Dialog (dlg)
	

	Select Case button
	Case -1 'ok button selected
		If dlg.DropListBox1 = "" Then
		MsgBox "Please select an SSN field",48,"Problem"
		GoTo mapping_start
		End If
			'get variable
			SSNField = fieldlist1$(dlg.DropListBox1)
	Case 0 'cancel button
		exit_script = true
		GoTo end_function

	GoTo mapping_start
End Select

end_function

End Function