Unbound forms in access project

  • Thread starter Thread starter Sergio Florez
  • Start date Start date
S

Sergio Florez

I have to create an access project and I'm totally blank
on the subject.

I know I have to use unbound forms so I can reflect the
speed of ADO and SQL Server, but I have no idea how to
make my recordsets the sources for forms and comboboxes.

Hopefully someone can give me ahand here or point me to
the right online sources since I've had no luck finding
them on my own.

If you can, I would very much love to see some sample
code on how to bind a form and a combobox to a recordset.

Thank you (whoever).
 
TRY THIS:

I am assuming you will be displaying one record at a time
based on some control you have on your form (e.g. a
combobox). Use the afterupdate event to fire event code
that resembles the following. If not basing this on a
controil and displaying all records, you could try an
onopen event for the form. Just a suggestion.

dim db as database

dim rst as recordset

dim sqlString as string

set db=currentDB

sqlString = "Select tableName.* from tablename where
tableName.fieldName= '" & formfield & "';"

note,there is no space between the single and double
quotes, but there is a space between the form name and the
ampersand as well as the ampersand and the double quotes.

set rst=db.openrecordset(sqlString,dbopensnapshot)

the snapshot recordset is not updatable, and safer.

then to set the fields on the form equal to the
appropriate field in the table so the following:

formfield1=rst!recordset field name1
formfield2=rst!recordset field name2

appropriate sintax must of course be used for the form
field names. If unsure of the sintax to use you can usee
the builder and select the field from the builder. ALso,
if the event setting this information is fired from the
form where the data is to be displayed, you can use the
following:

Me!field1=rst!recordset field name 1

etc...

to update any changes, use a querydef

dim qdf as querdef

dim sqlstring2 as string

sqlstring2 = "some action query"

set qdf=db.createquerydef("",sqlstring2)
qdf.execute

I hope this helps!
 
I know I have to use unbound forms so I can reflect the
speed of ADO and SQL Server, but I have no idea how to
make my recordsets the sources for forms and comboboxes.

What does this mean? Are you suggesting that you would save time using an
unbound form and a bunch of VBA to query the database, assign the values to
the textboxes and format them, detect any changes and manage all the saving
afterwards..? Always hoping, of course, that you didn't miss out one field
or get it in the wrong order or forget the formatting. Oh, and don't forget
to trap the IsNull errors on required fields. And key violations. And
foreign keys. And perhaps you'd like to intercept all the RowSource
properties for lists and combos and turn them into ValueLists -- or even a
List Function?

I'm sorry, but ADPs were designed for working with SQL server, and I can't
see any advantage in trying to re-invent the wheel.

All the best


Tim F
 
Back
Top