Filling a text box on a form with VBA code

C

Chrisso

Hi all

I dont understand why the code below does not work.

I have a form (Form1) with a text box (Text0). In my code I want to
open the form and display the text "Hello" in Text0.

However when I run this code Form1 comes up with Text0 blank. What am
I missing? What dont I understand? AS you can see I have tried a few
different ways of forcing this to happen with no available.

Form_Form1.Text0.DefaultValue = "Hello"
DoCmd.OpenForm Form_Form1.Name
Form_Form1.Text0.DefaultValue = "Hello"
Form_Form1.Repaint
DoEvents

I want to populate this form with data for a query to use. I want to
open the form, populate it with data into text boxes, run queries that
use this information then close the form.

Thanks for any help as I am stuck!

Chrisso
 
@

@Alex

Hi all

I dont understand why the code below does not work.

I have a form (Form1) with a text box (Text0). In my code I want to
open the form and display the text "Hello" in Text0.

However when I run this code Form1 comes up with Text0 blank. What am
I missing? What dont I understand? AS you can see I have tried a few
different ways of forcing this to happen with no available.

    Form_Form1.Text0.DefaultValue = "Hello"
    DoCmd.OpenForm Form_Form1.Name
    Form_Form1.Text0.DefaultValue = "Hello"
    Form_Form1.Repaint
    DoEvents

I want to populate this form with data for a query to use. I want to
open the form, populate it with data into text boxes, run queries that
use this information then close the form.

Thanks for any help as I am stuck!

Chrisso

The first row of your code can't work... if the Form is closed you
don't ger ERROR...?

Second to set DefaultValue property if Value is String you must add
chr(34)

Me!ControlName.DefaultValue = Chr$(34) & Me!ControlName & Chr$(34)

@Alex
 
C

Chrisso

Hi Alex and others

Sorry I made a mistake with pasteing in the code as I made some
changes to try all avenues before I posted.

I was not attempting to set DefaulValue but rather just .Value:

Form_Form1.Text0.Value = "Hello"
DoCmd.OpenForm Form_Form1.Name
Form_Form1.Text0.Value = "Hello"
Form_Form1.Repaint
DoEvents

I do not get any error in MS Access 2003 on the 1st line Alex.

Why wont my form display Hello in Text0?

Chrisso
 
@

@Alex

Hi Alex and others

Sorry I made a mistake with pasteing in the code as I made some
changes to try all avenues before I posted.

I was not attempting to set DefaulValue but rather just .Value:

    Form_Form1.Text0.Value = "Hello"

If here the Form_Form1 is not just Open you can't do it... you cant
refere to an object not open.
the error message must be displaied, but you must insert the Error
menaging... On Error....
    DoCmd.OpenForm Form_Form1.Name

This is wrong... if Form is not open also properties are not
allowed... and Name is form property...!

Try this code:
Docmd.OpenForm "Form1"
Forms("Form1")!Text0.Value="Hello"

No REPAINT are required for textBox changing...
    Form_Form1.Text0.Value = "Hello"
    Form_Form1.Repaint
    DoEvents

I do not get any error in MS Access 2003 on the 1st line Alex.

Why wont my form display Hello in Text0?

Chrisso

Bye

@Alex
 

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

Similar Threads

Textbox problem 1
Text Property 5
Round Fuction: Did I find a Bug??? 6
Query behind form 2
Get Numbers from G-code 5
dlookup problem 2
Problems filtering continuous form 1
Text box name & variables 3

Top