Re: Best Practices on updating tables



On Mon, 30 Jul 2007 19:50:01 -0700, rich <rich@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:

I added a hidden text box and for the After Update event for the
cboCompanyName, I set the text box = to the cbo and then issue the
DoCmd.Save. Opening the table confirms that the data was saved to the table.
Is this generally a good approach?

Frankly... NO.

Your table should have a CompanyID field, bound to the combo box which will
store the CompanyID. It is neither necessary nor appropriate to also store the
company name. The company name should exist in the company table, and *only*
in the company table; you can *display* it on the form by simply using a combo
box with the company name as the first (or only) visible field. There's no
need to display the companyID unless it's meaningful to the user.

You can use unbound textboxes on the form, if you wish, to display other
fields from the combo - set their control source to =combobox.Column(n) where
n is the zero based index of the field. But you wouldn't ordinarily store this
data redundantly.

What's a good best practice or method
for validating the success of a query (update, insert, and delete)? In VBS,
you can check the values in Err.code, does the same exist in Access VB?

If you're running the query from VBA code, yes:

Dim db As DAO.Database
Dim qd As DAO.Querydef
On Error GoTo Proc_Error
' create your action query
strSQL = "INSERT INTO <whatever>"
Set db = CurrentDb
' create an unnamed querydef object
Set qd = db.CreateQuerydef("", strSQL)
' execute the querydef object; if there's an error, raise the module's
' Error condition and jump to proc_error
qd.Execute dbFailOnError
Proc_Exit:
Exit Sub
Proc_Error:
MsgBox Err.Number, Err.Description
Resume Proc_Exit

HOWEVER - with a bound form you do not *need* this; you don't need any code at
all; the form *will display what has been put into the table*. I never have
felt the need to put verification code to check that what's on the form is
actually in the table; after all, the form is just a window which displays
what's in the table (often with combos or other tools to display it in a
human-friendly way). What you see is what you got!

Honestly - *it is easier than you're making it*. If you're used to having to
do everything yourself in code, relax - let Access do the gruntwork; that's
what it's designed to do, and it does it quite well.

John W. Vinson [MVP]
.



Relevant Pages

  • Re: Populating fields from a separate table
    ... You don't need store the existing data in the second table, ... To display the data create a query with Table two and table one as the ... set the join type to a left join on the 3 digit column. ...
    (comp.databases.ms-access)
  • Involved query / possible over Access assistance.
    ... This is the idea I want to try to implement in an access database. ... I want to store the dayof the week that the event ... I want to then do a query for a given week. ... point during the week 1) display which dayof the week, ...
    (microsoft.public.access.queries)
  • Re: SQL query to format datetime
    ... The data is not stored with any particular format - the format ... If you simply want to display 1/25/2005 when retrieving the datetime ... If you want to change the actual value, and store just the date, ... >Can I ask you a simple SQL query question? ...
    (microsoft.public.sqlserver.programming)
  • Count and display different services
    ... I have created a form based on a query. ... of times the clerk provided each service. ... The query asks for the clerks name, store ID, and the beginning and ... The results display the each service name and the count of each ...
    (microsoft.public.access.queries)
  • Count and display different services
    ... I have created a form based on a query. ... of times the clerk provided each service. ... The query asks for the clerks name, store ID, and the beginning and ... The results display the each service name and the count of each ...
    (microsoft.public.access.forms)

Quantcast