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.
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
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
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.
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:
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
dlg.Show
Do
Set msg = dlg.GetMsg()
dlg.Control("copyright", "metaiptc").Value = "Hello"
Loop While msg
End Function
[/code]
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.
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