Microsoft Access Office VB VBA Help and Examples
           
             

The trouble with assigning values to objects

The third in an occasional series of rants by Chris Shepherd

For my third column Id like to take a look at the simple act of assigning a value to a field using VBA. Ahhh, simple stuff I here you say.
So we want to change the value in a text box from command button. Simple we just write some code like this:

Private Sub Command13_Click()
   Me.FirstName.Text = "Test"
End Sub

The Trouble with Access is that when you run this code you get the Oh so useful and user friendly message:

Which is the access way of saying "I know we said we use Visual Basic but at this point wed really like to do our own thing". Someone please explain why do I have to move to a control to change it ?

Luckily the solution to this (thanks to John Hawkins) is quite simple:

Private Sub Command13_Click()
   Me.FirstName.Value = "Test"
End Sub

An easy fix I know but helpful none the less.

If you have any comments about this article or would like to suggest other niggles with Access please Contact Chris Shepherd

Chris Shepherd is a Technical Consultant working for SCC in the UK. He is an MCP in Access, VB, Excel and is a fully paid up member of the Access fan club.

 
HOME   SEARCH SITE   PRIVACY POLICY   CONTACT
The code and application content of this site is copyright of Smiley I.T. and as such reproduction in any form which is for commercial use requires the permission of the Webmaster. Any use of this code for non-commercial use only requires a link or comment back to the original page you took the code from.