Connecting Tech Pros Worldwide Help | Site Map

please help

crispycomputers@hotmail.com
Guest
 
Posts: n/a
#1: Nov 13 '05
i am creating a database for a school registration system. i have
created a form. on the form i have created a button. i want this button
to:

create a new record in the relevent table, then copy one of the fields
in the form to one of the fields in the table. (the table which the
form is pointed to is not the same table which the button is going to)

thank you

Johnny Meredith
Guest
 
Posts: n/a
#2: Nov 13 '05

re: please help


You'll have to do this with code. Make sure you have a reference set
to DAO (Tools -> References; put a checkmark in Microsoft DAO 3.6).

In the form's declaration section type:

Public Const cDestinationTable = "MyTable"
'Replace MyTable with name of destination table
Public Const cDestinationField = "MyField"
'Replace MyField with name of field in destination table

In the button's onclick event, type (air code):

Dim db as DAO.Database
Dim rec as DAO.Recordset
Dim conMyControl as Control
conMyControl = me.MyControl 'Change MyControl to the control with
the value
Set db = CurrentDB()
With db
Set rec = .OpenRecordSet(cDestinationTable)
With rec
.AddNew
.Fields(cDestinationField) = conMyControl
.Update
.Close
End With
.Close
End With
Set rec = Nothing
Set db = Nothing

Right click on the button you are programming and select Build Event,
then code builder, to get to the buttons onclick event. The
declarations section is the whitespace at the top of this window below
any option statements (Option Explicit, Option Compare Database, etc.)
This should get you started, but please ask any follow-up questions you
need.

Johnny

Closed Thread