Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / June 2004

Tip: Looking for answers? Try searching our database.

programmatically adding line objects to a form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Hughes - 03 Jun 2004 23:26 GMT
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
MacDermott - 04 Jun 2004 00:06 GMT
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

> 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.
david epsom dot com dot au - 04 Jun 2004 08:33 GMT
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)

> 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.
Mike Hughes - 04 Jun 2004 16:56 GMT
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
david epsom dot com dot au - 07 Jun 2004 00:29 GMT
> 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)

> 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...
>
[quoted text clipped - 8 lines]
>
>      (david)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.