Edit control in form

I have an edit control in a form and several variables containing text.

I want to plug the edit control with the text in one of these variables depending on certain circumstances. ( I can work out how to do that bit)

What I cannot figure out is the VB code to get the variable value into the field. I have been thrashing around the site and the help files for hours to no avail.

Can anyone offer any suggestions

Assuming Opus 12.0.7, I think it is editControl.value = "My Text"

I used this snippet of code to test filling a form field. The form is called metaiptc and the filed is called copyright

Function OnClick(ByRef ClickData) Set dlg = ClickData.Func.Dlg Set Dlg = DOpus.Dlg Dlg.window = clickData.func.sourcetab Dlg.template = "metaiptc" Dlg.Show dlg.control ("metaiptc", "copyright").EditContol.value = "My Text" End Function

When I run the code the form appears but the copyright field contains nothing

What VB faux pas I am committing, please?

See the section in the Opus 12 release notes on the difference between simple and detached dialogs. You need to detach the dialog and run a message loop if you want to interact with the controls programatically.

(additionally, the .EditContol isn't needed; even if it were spelt right it wouldn't do anything).

Tried to follow the example code with no luck. the Copyright box is always empty

Function OnClick(ByRef clickData) Set dlg = DOpus.Dlg dlg.window = clickData.func.sourcetab dlg.template = "metaiptc" dlg.detach = true dlg.Show Do Set msg = dlg.GetMsg() 'dlg.Control("metaiptc", "copyright").Value = "Hello" Loop While msg End Function

Is the line that sets the value supposed to be commented out?

Sorry no. But it does not work anyway.

It looks like you have the arguments for the Control method around the wrong way. Control name first, followed by dialog name (if needed).

Wow, sorry, Jon this really has me confused:

I do not really get what you mean, being a total newcomer to VB and painfully trying to hack my way into it. The following code:

Function OnClick(ByRef clickData) Set dlg = DOpus.Dlg dlg.window = clickData.func.sourcetab dlg.template = "metaiptc" dlg.detach = true dlg.Show Do Set msg = dlg.GetMsg() dlg.Control.Value("metaiptc","copyright") = "Hello" Loop While msg End Function

Produces the following error:

Error at line 9, position 1
Invalid procedure call or argument: 'dlg.Control' (0x800a0005)

It is probably just that I am not understanding your instructions.

I meant that you need to swap the arguments (the values you are passing) to the Control method.

You originally had:

dlg.Control("metaiptc", "copyright").Value = "Hello"

But the method is documented as taking the control name as the first argument, and the dialog name as the second argument. As far as I can tell, "metaiptc" is the name of the dialog, and "copyright" is the control. So what this should actually be is:

dlg.Control("copyright", "metaiptc").Value = "Hello"

I did not misunderstand your previous message. I had already tried your most recent suggestion of changing round the form name and dialog entry name, but it simply does not work.

Even with the fields switched around the copyright field remains empty and there is an error message generated. In other words switching the fields around makes no difference, so, obviously the problem lies elsewhere. But where is beyond me.

This is the code as you suggest: [code]Function OnClick(ByRef clickData)
Set dlg = DOpus.Dlg
dlg.window = clickData.func.sourcetab
dlg.template = "metaiptc"
dlg.detach = true
Set msg = dlg.GetMsg()

dlg.Control("copyright", "metaiptc").Value = "Hello"
Loop While msg
End Function

And this is the error message

Error at line 10, position 1
Invalid procedure call or argument: 'dlg.Control' (0x800a0005)

Could I make a very small suggestion? In the documentation the example you give involves a form called "books and a control also called "books". It would make things plainer for a dolt like me if they had different names.

In the meantime I would be very grateful for any help in what is actually wrong.

It might be easier if you give the full example including the resource XML that defines the dialog you're trying to control, so we can see all the details and also run the code ourselves.

If it's in a button, you should be able to right-click it (while still in Customize mode) and copy it to the clipboard, then paste that here.

The button is here:

<?xml version="1.0"?> <button backcol="none" display="both" label_pos="right" separate="yes" textcol="none"> <label>New Button</label> <icon1>#newcommand</icon1> <function type="script"> <instruction>@script VBScript</instruction> <instruction>Function OnClick(ByRef clickData)</instruction> <instruction>Set dlg = DOpus.Dlg</instruction> <instruction>dlg.window = clickData.func.sourcetab</instruction> <instruction>dlg.template = &quot;metaiptc&quot;</instruction> <instruction>dlg.detach = true</instruction> <instruction>dlg.Show</instruction> <instruction>Do</instruction> <instruction>Set msg = dlg.GetMsg()</instruction> <instruction /> <instruction>dlg.Control(&quot;copyright&quot;, &quot;metaiptc&quot;).Value = &quot;Hello&quot;</instruction> <instruction>Loop While msg</instruction> <instruction>End Function</instruction> <instruction /> <instruction>==SCRIPT RESOURCES</instruction> <instruction>&lt;resources&gt;</instruction> <instruction> &lt;resource name=&quot;Metaiptc&quot; type=&quot;dialog&quot;&gt;</instruction> <instruction> &lt;dialog fontsize=&quot;10&quot; height=&quot;220&quot; lang=&quot;english&quot; standard_buttons=&quot;ok,cancel&quot; title=&quot;ENTER IPTC METADATA&quot; width=&quot;325&quot;&gt;</instruction> <instruction> &lt;control halign=&quot;left&quot; height=&quot;8&quot; name=&quot;static1&quot; title=&quot;Enter the IPTC metadata, and click a button.&quot; type=&quot;static&quot; width=&quot;159&quot; x=&quot;9&quot; y=&quot;6&quot; /&gt;</instruction> <instruction> &lt;control halign=&quot;left&quot; height=&quot;12&quot; name=&quot;copyright&quot; tip=&quot;Copyright Holder&quot; type=&quot;edit&quot; width=&quot;185&quot; x=&quot;60&quot; y=&quot;27&quot; /&gt;</instruction> <instruction> &lt;control halign=&quot;left&quot; height=&quot;30&quot; max=&quot;512&quot; multiline=&quot;yes&quot; name=&quot;caption&quot; type=&quot;edit&quot; width=&quot;243&quot; x=&quot;18&quot; y=&quot;92&quot; /&gt;</instruction> <instruction> &lt;control halign=&quot;left&quot; height=&quot;8&quot; name=&quot;static2&quot; title=&quot;Copyright:&quot; type=&quot;static&quot; width=&quot;37&quot; x=&quot;15&quot; y=&quot;27&quot; /&gt;</instruction> <instruction> &lt;control halign=&quot;left&quot; height=&quot;8&quot; name=&quot;static3&quot; title=&quot;Caption:&quot; type=&quot;static&quot; width=&quot;33&quot; x=&quot;20&quot; y=&quot;80&quot; /&gt;</instruction> <instruction> &lt;control halign=&quot;left&quot; height=&quot;8&quot; name=&quot;static4&quot; title=&quot;Subject:&quot; type=&quot;static&quot; width=&quot;26&quot; x=&quot;19&quot; y=&quot;135&quot; /&gt;</instruction> <instruction> &lt;control halign=&quot;left&quot; height=&quot;12&quot; name=&quot;subject&quot; tip=&quot;Enter the Subject&quot; type=&quot;edit&quot; width=&quot;252&quot; x=&quot;52&quot; y=&quot;134&quot; /&gt;</instruction> <instruction> &lt;control halign=&quot;left&quot; height=&quot;12&quot; name=&quot;photog&quot; tip=&quot;Photographer&amp;apos;s name&quot; type=&quot;edit&quot; width=&quot;123&quot; x=&quot;71&quot; y=&quot;45&quot; /&gt;</instruction> <instruction> &lt;control halign=&quot;left&quot; height=&quot;8&quot; name=&quot;Photographer&quot; title=&quot;Photographer&quot; type=&quot;static&quot; width=&quot;44&quot; x=&quot;17&quot; y=&quot;47&quot; /&gt;</instruction> <instruction> &lt;control halign=&quot;left&quot; height=&quot;8&quot; name=&quot;Title&quot; title=&quot;Title:&quot; type=&quot;static&quot; width=&quot;22&quot; x=&quot;23&quot; y=&quot;160&quot; /&gt;</instruction> <instruction> &lt;control halign=&quot;left&quot; height=&quot;12&quot; name=&quot;title&quot; tip=&quot;Enter the Title&quot; type=&quot;edit&quot; width=&quot;115&quot; x=&quot;56&quot; y=&quot;158&quot; /&gt;</instruction> <instruction> &lt;control halign=&quot;left&quot; height=&quot;8&quot; name=&quot;static7&quot; title=&quot;Keywords:&quot; type=&quot;static&quot; width=&quot;35&quot; x=&quot;19&quot; y=&quot;184&quot; /&gt;</instruction> <instruction> &lt;control halign=&quot;left&quot; height=&quot;12&quot; name=&quot;keyword&quot; tip=&quot;Add keywords separated by semi-colons&quot; type=&quot;edit&quot; width=&quot;246&quot; x=&quot;63&quot; y=&quot;182&quot; /&gt;</instruction> <instruction> &lt;control halign=&quot;left&quot; height=&quot;8&quot; name=&quot;static8&quot; title=&quot;rec sets copyright and photographer to Rodger Clark&quot; type=&quot;static&quot; width=&quot;237&quot; x=&quot;74&quot; y=&quot;57&quot; /&gt;</instruction> <instruction> &lt;/dialog&gt;</instruction> <instruction> &lt;/resource&gt;</instruction> <instruction>&lt;/resources&gt;</instruction> </function> </button>

Basically what I am trying to do is to create my own IPTC data entry form that gives me the ability to have a multi-line caption field, which makes text entry much easier than the metadata panel, when the caption is pretty long. Going along the single line field to alter words here and there can be a frustrating experience, I find.

I have that part working just fine. But to add to it I would like to check if any of the IPTC fields I am interested in already contain data, and if they do I want to plug that data in the form.

The code on this button is an attempt to plug just one field - copyright. The eventual idea is to gather any values in the IPTC fields into variables and then plug the fields in the form with those variables. ( With your help, I have a code snippet to do that part)

The error is because you're specifying "metaiptc" as the second argument for the Control method. This is only intended for use when you have a tab control in your dialog - it's to let you specify which child dialog hosts the control you're referring to. Since you don't have a tab on your dialog you should leave this parameter out.

If you try the following code it should work for you:

Function OnClick(ByRef clickData) Set dlg = clickData.func.Dlg ' Better than DOpus.Dlg if running from a button ' dlg.window = clickData.func.sourcetab ' Not needed if using clickData.func.dlg dlg.template = "metaiptc" dlg.detach = true dlg.Show dlg.Control("copyright").value = "Hello" Do Set msg = dlg.GetMsg() Loop While msg End Function

Sir, you are a scholar and a gentleman. Thank you so much.