Loading form fields from table

BIGGY

Registered User.
Local time
Today, 13:17
Joined
Jul 11, 2003
Messages
25
I have a single record table/multi field table which I'm trying to load into text boxes for the user to edit. Any way to get this code to work? I know that it works the other way around, but wasn't sure how to load fields into a form.

Private Sub Form_Load()
Dim MyDB As DAO.Database

Dim MySet1 As DAO.Recordset
Dim strSQl As String

Set MyDB = CurrentDb

Set MySet1 = MyDB.OpenRecordset("tblAdams")

DoCmd.SetWarnings False

Me.TraNamFld = !TradeName
Me.ComNamFld = !CompleteCoName
Me.StrFld = !AddressStreet
Me.CitFld = !AddressCity
Me.StaFld = !AddressState
Me.ZipFld = !AddressZip
Me.TelFld = !Telephone
Me.FaxFld = !Facsimile
Me.ResFld = !ResaleTaxNo
Me.DbdFld = !DBDunsNo
Me.EidFld = !EIDNo

MySet1.Close


Set MySet1 = Nothing

DoCmd.SetWarnings True
End Sub
 
I know this isn't what you asked but here's another option: Use tblAdams as the form's Record Source property.

Me.RecordSource = "tblAdams"

Regards,
Tim
 
You didn't open the recordset and you are not using with so you can't omit the recordset name when referencing its fields.

I'm sure this is a stupid question but why aren't you using a bound form?
 
No, not a stupid question at all. Maybe the answer is though :) Well, I know pretty much nothing about Access or VB. Everything I know is picked up on my own, so I teach myself as I go. I couldn't even tell ya what a bound form is without looking it up.
 
In Access a bound form is the natural order of things. If you choose a RecordSource (table or query) when you create the form, it is "bound" to that RecordSource. You can drag fields from the field list and they are also bound. Or, you can just let one of the wizards build the form and adjust its format later. When you open the form, Access opens the RecordSource and populates all the bound controls with data from the appropriate column in the RecordSource. You don't need to do anything. The form will normally be editable (certain types of queries produce Recordsets that do not support modifications).
 

Users who are viewing this thread

Back
Top Bottom