Using a button to copy contents of one file into another.

A

Avid Fan

I have a form with 2 address physical address and Mailing address.

Frequently the two are the same thing.


So I want to have a button that copies the data across.

Private Sub cmdCopy_Click()
Me.Address2.Text = Me.Address1
Me.cboSuburb2.Text = Me.cboSuburb1.Text
Me.State2.Text = Me.State1.Text
End Sub


Does not work I get an error 2185 that says

"You can't reference a property or method of a control if the control
does not have focus"


Any ideas?
 
A

Avid Fan

I have a form with 2 address physical address and Mailing address.

Frequently the two are the same thing.


So I want to have a button that copies the data across.

Private Sub cmdCopy_Click()
Me.Address2.Text = Me.Address1
Me.cboSuburb2.Text = Me.cboSuburb1.Text
Me.State2.Text = Me.State1.Text
End Sub


Does not work I get an error 2185 that says

"You can't reference a property or method of a control if the control
does not have focus"


Any ideas?


Solved it replace text with value and it all works fine.

Wonder why what the thinking behind text and value is. I mean why are
they different? I mean would not one do?
 
L

Linq Adams via AccessMonster.com

Basically, in Access VBA, ***Value*** is the data that resides in the field
underlying the textbox. It can be referenced in code from anywhere in the
form's code module..

***Text*** is the data that shows in the textbox while it has focus.

For instance, if a textbox holds

John Doe

and you go in and edit the textbox to

Jane Doe

and stop, with the cursor still in the textbox,

Value = John Doe

but

Text = Jane Doe

***Text*** is only used in Access VBA when you're doing something while the
textbox has the focus, but you leave it and the textbox is updated. One
example would be if you wanted to keep track and let the user know how many
more characters could be added before reaching the limit, ala a website
'comment box'

You would

Place a label above or next to the textbox.
Make the label's caption "255 Characters Left"
Place this code behind the textbox:

Private Sub YourTextBox_Change()
CharacterCountLabel.Caption = 255 - Len(Me.YourTextBox.Text) & " Characters
Left"
If Len(Me.YourTextBox.Text) = 255 Then
MsgBox "No more characters allowed!"
End If
End Sub.
 
A

Avid Fan

Basically, in Access VBA, ***Value*** is the data that resides in the field
underlying the textbox. It can be referenced in code from anywhere in the
form's code module..

***Text*** is the data that shows in the textbox while it has focus.

For instance, if a textbox holds

John Doe

and you go in and edit the textbox to

Jane Doe

and stop, with the cursor still in the textbox,

Value = John Doe

but

Text = Jane Doe

***Text*** is only used in Access VBA when you're doing something while the
textbox has the focus, but you leave it and the textbox is updated. One
example would be if you wanted to keep track and let the user know how many
more characters could be added before reaching the limit, ala a website
'comment box'

You would

Place a label above or next to the textbox.
Make the label's caption "255 Characters Left"
Place this code behind the textbox:

Private Sub YourTextBox_Change()
CharacterCountLabel.Caption = 255 - Len(Me.YourTextBox.Text)& " Characters
Left"
If Len(Me.YourTextBox.Text) = 255 Then
MsgBox "No more characters allowed!"
End If
End Sub.

Thank you.

I have recieved so much help here. I really appreciate it.
 

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