using VBA to change property of a field

  • Thread starter bmelv via AccessMonster.com
  • Start date
B

bmelv via AccessMonster.com

hey,
im trying to change the 'control source' of the field "balance" from the form
"HSBC Form" at the click of a button...
here's my code so far:


Private Sub Command13_Click()
[Forms]![HSBC Form]![Balance].ControlSource = 6509

End Sub

when i click the button it comes up with the #Name? error, any thoughts on
why this is happening?

thanks,
b
 
S

strive4peace

Hi B (what is your name?)

'~~~~~~~~~~~~~~~~~~
Sub Form_ChangeControlSourceOnForm()
Dim frm As form
DoCmd.OpenForm "Formname", acViewDesign
Set frm = Forms("Formname")
frm.Balance.ControlSource = "6509"
'
DoCmd.Save acForm, "Formname"
DoCmd.Close acForm, "Formname"
Set frm = Nothing
msgbox "Done"
End Sub
'~~~~~~~~~~~~~~~~~~

is 6509 a fieldname? a number?

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*
 
D

Douglas J. Steele

Actually, if 6509 is a number, you'd need

frm.Balance.ControlSource = "=6509"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


strive4peace said:
Hi B (what is your name?)

'~~~~~~~~~~~~~~~~~~
Sub Form_ChangeControlSourceOnForm()
Dim frm As form
DoCmd.OpenForm "Formname", acViewDesign
Set frm = Forms("Formname")
frm.Balance.ControlSource = "6509"
'
DoCmd.Save acForm, "Formname"
DoCmd.Close acForm, "Formname"
Set frm = Nothing
msgbox "Done"
End Sub
'~~~~~~~~~~~~~~~~~~

is 6509 a fieldname? a number?

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*



hey,
im trying to change the 'control source' of the field "balance" from the
form
"HSBC Form" at the click of a button...
here's my code so far:


Private Sub Command13_Click()
[Forms]![HSBC Form]![Balance].ControlSource = 6509
End Sub

when i click the button it comes up with the #Name? error, any thoughts
on
why this is happening?

thanks,
b
 
B

bmelv via AccessMonster.com

cheers, i put that in but it came up with the error message:

Run-time error 2102:

The form name "[ledger]" is misspelled or refers to a From that doesn't exist.



I've spelt it right and it does exist!!
What i'm actually trying to do is change the RecordSource of the form [ledger]
, i just thought if i could change the control source of that field first i
might be able to figure how to do it on the actual form. sorry if this has
confused you a bit..!!! but any ideas?

cheers
b
p.s the names bobbie!
Actually, if 6509 is a number, you'd need

frm.Balance.ControlSource = "=6509"
Hi B (what is your name?)
[quoted text clipped - 41 lines]
 
B

bmelv via AccessMonster.com

thats sposed to be 'Form' not 'From' in the error message as well!!
cheers, i put that in but it came up with the error message:

Run-time error 2102:

The form name "[ledger]" is misspelled or refers to a From that doesn't exist.

I've spelt it right and it does exist!!
What i'm actually trying to do is change the RecordSource of the form [ledger]
, i just thought if i could change the control source of that field first i
might be able to figure how to do it on the actual form. sorry if this has
confused you a bit..!!! but any ideas?

cheers
b
p.s the names bobbie!
Actually, if 6509 is a number, you'd need
[quoted text clipped - 5 lines]
 
S

strive4peace

did you compile your code?


'~~~~~~~~~ Compile ~~~~~~~~~

Whenever you change code, references, or switch versions, you should
always compile before executing.

from the menu in a VBE (module) window: Debug, Compile

fix any errors on the yellow highlighted lines

keep compiling until nothing happens (this is good!)

~~
if you run code without compiling it, you risk corrupting your database


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*



thats sposed to be 'Form' not 'From' in the error message as well!!
cheers, i put that in but it came up with the error message:

Run-time error 2102:

The form name "[ledger]" is misspelled or refers to a From that doesn't exist.

I've spelt it right and it does exist!!
What i'm actually trying to do is change the RecordSource of the form [ledger]
, i just thought if i could change the control source of that field first i
might be able to figure how to do it on the actual form. sorry if this has
confused you a bit..!!! but any ideas?

cheers
b
p.s the names bobbie!
Actually, if 6509 is a number, you'd need
[quoted text clipped - 5 lines]
thanks,
b
 

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