programmatically adding line objects to a form

G

Guest

Hello

I'm really stuck. I'm attempting to make a quick drawing program using the line object provided in the toolbox but I also want to be able to add lines in code (ie. Dim newLine As Line) but I can't seem to figure out a way to do it

If I do a "Dim newLine As Line" and then try to edit it's properties (ie. newLine.Visible = true) then the program errors at runtime with the error "Object variable or With block variable not set

If I try to do a "Set newLine = New Line" after the Dim then the program has another runtime error "ActiveX component can't create object"

I've looked high and low and tried almost everything but I still can't get it to work. It's probably something really simple but I'm not a VB programmer usually so the smallest things trip me up at times

Thanks for any help you can provide.
 
M

MacDermott

In Access, you can't add controls to a form at runtime, only at design time.
Access programmers sometimes "work around" this problem by putting controls
they may need later on the form at design time, and setting their Visible
property to False until they're needed.

If you need to stay on the VB side of things, you might try building your
application in VB6.0 or VB.NET, where you can have an array of controls, and
load additional members to it. You can also draw lines & circles on the
screen - as you can on Access Reports (but not on forms).
I'm not a C-type programmer myself, but I suspect that's really the best
environment for building an application like the one you describe.

HTH
- Turtle


Mike Hughes said:
Hello,

I'm really stuck. I'm attempting to make a quick drawing program using
the line object provided in the toolbox but I also want to be able to add
lines in code (ie. Dim newLine As Line) but I can't seem to figure out a way
to do it.
If I do a "Dim newLine As Line" and then try to edit it's properties (ie.
newLine.Visible = true) then the program errors at runtime with the error
"Object variable or With block variable not set"
If I try to do a "Set newLine = New Line" after the Dim then the program
has another runtime error "ActiveX component can't create object".
I've looked high and low and tried almost everything but I still can't get
it to work. It's probably something really simple but I'm not a VB
programmer usually so the smallest things trip me up at times.
 
D

david epsom dot com dot au

If you are sure you want to use the line object like this,
use CreateControl to Add a control

docmd.OpenForm "form1",acDesign 'switch to design
set ctl = createcontrol "from1", acLine ......
docmd.OpenForm "form1",acnormal 'switch back to normal

(david)


Mike Hughes said:
Hello,

I'm really stuck. I'm attempting to make a quick drawing program using
the line object provided in the toolbox but I also want to be able to add
lines in code (ie. Dim newLine As Line) but I can't seem to figure out a way
to do it.
If I do a "Dim newLine As Line" and then try to edit it's properties (ie.
newLine.Visible = true) then the program errors at runtime with the error
"Object variable or With block variable not set"
If I try to do a "Set newLine = New Line" after the Dim then the program
has another runtime error "ActiveX component can't create object".
I've looked high and low and tried almost everything but I still can't get
it to work. It's probably something really simple but I'm not a VB
programmer usually so the smallest things trip me up at times.
 
G

Guest

Thanks for the replies

So David, does that mean that I really can't add a control to my form unless I shut down the form, add the control, and then re-open the form? I guess the other way I could do it would be to create a subform off my main form and then just add the control to that sub form during the design phase of the form. This seems like a really odd way of doing things. Oh well, I guess I'll have to work around this but thanks to both of you for your replies

Thanks..


----- david epsom dot com dot au wrote: ----

If you are sure you want to use the line object like this
use CreateControl to Add a contro

docmd.OpenForm "form1",acDesign 'switch to desig
set ctl = createcontrol "from1", acLine .....
docmd.OpenForm "form1",acnormal 'switch back to norma

(david
 
D

david epsom dot com dot au

So David, does that mean that I really can't add a control to my form
unless I shut down the form, add the control, and then re-open the form? I
guess the other way I could do it would be to create a subform off my

No, Yes.

I guess it really means that I don't think you WANT to use a line object.
But we used to do stuff like this before we switched to MDE's.

I'll add that you use
DoCmd.Echo False
.....
DoCmd.Echo True

so that the form doesn't flash when you change modes,

And when you close the form you use acSaveNo

In answer to your specific question, NO, you do not shut down the form: you
just change modes. like changing from view to datasheet mode. No, that does
not trigger load/open events. No, that does not unload the code object. But
yes, it does repaint the form.

If you DO want to use a line object, you should consider leaving several
hidden line objects on your form for use as required.

(david)


Mike Hughes said:
Thanks for the replies,

So David, does that mean that I really can't add a control to my form
unless I shut down the form, add the control, and then re-open the form? I
guess the other way I could do it would be to create a subform off my main
form and then just add the control to that sub form during the design phase
of the form. This seems like a really odd way of doing things. Oh well, I
guess I'll have to work around this but thanks to both of you for your
replies.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top