Accessing Tables with VBA Code

  • Thread starter Thread starter Chin Bhat
  • Start date Start date
C

Chin Bhat

Hi,

I am currently using the following code in my form:

Private Sub Form_Load()
Set dbs = CurrentDb
Set doc = dbs.Containers("Databases")!UserDefined


Me.PreSearchStores = doc.Properties!PRS
Me.PostSearchStores = doc.Properties!POS
..
..
..


I am trying to write to a table. Some values are entered
by the user and others are internal and are being written
using the code above. The problem is, the code above
always writes one record down from the rest of the data.
The CurrentRecord is 1 but it still writes on line down.
Can someone please help me fix this problem?

Thanks a lot.

Chin Bhat.
 
Hi Chin.

I think you're making this a little harder than it needs to be... but that's
ok!

I suggest creating a form with controls bound to each field on your table.
Those fields that are filled in by code can have their visible property = no,
(or if you want your user to see the values, but not be able to override
them, you can leave visible as yes, and set "Enabled = no" and "Locked =
yes") Then, set the default value = what the code would write into the table
field. The nice thing about using a form to enter your data is that you can
make the fields whatever sizes and types you need to to match the data, more
"user-friendly" if you will.

If the automatically entered data depends on the values of other fields
entered by the user, then you will need to use your code. Use one of the
event properties (like "lost focus") on the control that has the data needed
to automatically fill in the other(s) to execute the steps to find the
automatic value and shove it into the proper control .

I hope that makes sense! If you have more questions, leave a note, and I'll
check back here soon. :-)

Amanda
 
Back
Top