Hi.
I am filling out a PDF based on values in my form.
The form has 5 subforms, with a lot of controls on each.
The code works today, but it takes to much time to change.
The idea is that i reference each field in the form (each textbox control) by its name, and then i name the pdf field the same.
So the bottom half of the code below today lookes like this, and it fills out the pdf with customer information. Beneath I have one field per subform as an example. I would have maxed out the number of controls if i kept them in 1 form, therefore I have 5 subforms on my main form. The "button" is launched from the parent form.
First: this code works great today... but is difficult to maintain if the form changes, therefore i would like to improve my code.
Instead of naming each and every control to the same name in the pdf, I am trying to make the program understand that i would like it to do the same for EVERY control the same way, without me typing in everything.
It fails here:
with the error message: Object variable or with block variable not set, run-time error 91.
I guess I am not getting the "path" to the control correctly. the path/ control address should probably be converted to a string... anyone knows how to do this?
Anyone?
I am filling out a PDF based on values in my form.
The form has 5 subforms, with a lot of controls on each.
The code works today, but it takes to much time to change.
The idea is that i reference each field in the form (each textbox control) by its name, and then i name the pdf field the same.
So the bottom half of the code below today lookes like this, and it fills out the pdf with customer information. Beneath I have one field per subform as an example. I would have maxed out the number of controls if i kept them in 1 form, therefore I have 5 subforms on my main form. The "button" is launched from the parent form.
First: this code works great today... but is difficult to maintain if the form changes, therefore i would like to improve my code.
Code:
Print #intFile, "<field name=""accountID"">"
Print #intFile, "<value>" & Me!account.Form!accountID & "</value>"
Print #intFile, "</field>"
Print #intFile, "<field name=""selskapstype"">"
Print #intFile, "<value>" & Me!HVV.Form!selskapstype & "</value>"
Print #intFile, "</field>"
Print #intFile, "<field name=""InnsattBel"">"
Print #intFile, "<value>" & Me!idok.Form!InnsattBel & "</value>"
Print #intFile, "</field>"
Print #intFile, "<field name=""etTekst"">"
Print #intFile, "<value>" & Me!et.Form!etTekst & "</value>"
Print #intFile, "</field>"
Print #intFile, "<field name=""FO_tekst"">"
Print #intFile, "<value>" & Me!FOtekst.Form!FO_tekst & "</value>"
Print #intFile, "</field>"
'to close up it adds this at the bottom to open the pdf
Print #intFile, "</fields>"
Print #intFile, "</xfdf>"
Close #intFile
ShellEx strOutput
Exit Sub
Instead of naming each and every control to the same name in the pdf, I am trying to make the program understand that i would like it to do the same for EVERY control the same way, without me typing in everything.
Code:
Dim ctl_input As Access.Control
Dim ctl_ref As Access.Reference
'starts the loop
For Each ctl_input In Me.Controls
Print #intFile, "<field name=" & ctl_input.Name & ">"
Print #intFile, "<value>" & ctl_ref & "</value>"
Print #intFile, "</field>"
Next ctl_input
'continues until there is no more controls then adds the finishing lines
Print #intFile, "</fields>"
Print #intFile, "</xfdf>"
Close #intFile
ShellEx strOutput
Exit Sub
It fails here:
Code:
Print #intFile, "<value>" & ctl_ref & "</value>"
I guess I am not getting the "path" to the control correctly. the path/ control address should probably be converted to a string... anyone knows how to do this?
Anyone?