Creating a text box using a command button

barno_xvi

Registered User.
Local time
Today, 21:26
Joined
Aug 19, 2006
Messages
21
I'm having trouble creating a text box in a form that already exists. I've used the example from the microsoft help thing to create a text box in a new form, but for some reason I haven't been able to edit it to create it to do what I want. :confused: If anyone has done this I would be really helpful some advice or a slice of code :) cheers guys
 
Why not put the text box on the form; set its Visible Property = False and then use the Command Button to change the Visible property = True?
 
Code

The story so far;

I have a form called "Form" and I want to just put a square text box on to the form.


Dim frm As Form
Dim Box As Control
Set frm = "Form"
Set Box = CreateControl(frm.Name, acTextBox, , , , 1000, 1000, 1000, 1000)
DoCmd.Restore


I can't understand why it will not work.

The error I get from that code is: "Compile Error: Type mismatch"

When I tried taking the form name out of the speech marks -
Set frm = Form

I got the error "...Object required"

Thanks for the help
 
Hey. I need to actually create one of different size each time and in different places. Ambitious I know :o Thanks for that though
 
I take your point but unless you wish to allow an unlimited number of new text boxes, I would still do as I suggest and make them visible at the appropriate time. If you need to move them about, then code can be used to do that.

Just a thought.
 
Yeh I kinda do need unlimited text boxes. The reason for this would be;

I have a make-shift calendar with the dates down one side and for example, house numbers along the top. I need to create a textbox in the space on the calendar where the house is going to be occupied. And then be able to move them around after.

Can you think of any other way to do this?
I did try having lots of single text boxes and just changing the colour when they are "occupied" but I ran into the problem of seeing where one began and ended and it was quite lengthy. This was also a problem when I wanted to move them from say one "house" to another for some reason.

I was hoping to create the text box and store the information about its position in a table and then just edit the positions in a form. The positions would just be in the form of house numbers and dates. I think I can do this part, I just need to work out the first bit of creating the text boxes? Or do you have a better idea? Thanks for your help.
 
PHP:
Set frm = "Form"

Change the above to

PHP:
Set frm = Forms!Form
 
Oh!! Stupid me! :) Thanks for that. Can't believe I missed that.Cheers again
 
This seems to work

Create a Function in a Module

Function NewBox()
On Error GoTo NewBox_Err

DoCmd.OpenForm "Form1", acDesign, "", "", , acNormal
Dim frm As Form
Dim Box As Control
'Set frm = Form1 Don't need this line
Set Box = CreateControl("Form1", acTextBox, , , , 1000, 1000, 1000, 1000)
'DoCmd.Restore Don't need this line


DoCmd.Close acForm, "Form1", acSaveYes
DoCmd.OpenForm "Form1", acNormal, "", "", , acNormal

NewBox_Exit:
Exit Function

NewBox_Err:
MsgBox Error$
Resume NewBox_Exit

End Function


Apparantly you need to set the form to Design View to Create a new text box
 
Haha! That's wicked but I've never worked with functions before and although it's probably really simple to run one, I've tried and am having trouble. Can you just give me a quick example of how to run that function from a command button?

Thanks very much for your help
 
Sorry... another question;

Can I change the name of the text box that i create?

Thanks
 
Okay. I put the code from the function straight into the Command Button code, and did have the right way to change the name. So it all works!! Thanks for all your help. If you could still point the in the right direction to learn about functions I'd be really greatful. Cheers
 

Users who are viewing this thread

Back
Top Bottom