Quick Question - acOpenForm

D

Daniel

When I want to add a record by opening a form with one or
more of the fields taken from a field on the first form
how do I do that? e.g. When the user clicks on the New
Appt button on frmPt it should open frmAppt for an
addition with the fApptPtID set to fPtID. I have been
tinkering with the following to no avail:

Private Sub btnNewAppt_Click()
'Opens a new appointment form for the current patient
DoCmd.OpenForm "frmAppt", acNormal, , "fApptPtID" = Me!
fPtID, acFormAdd
End Sub

Where am I going wrong? and can I make multiple fields go
to the new form? Do I use the args section to set values
in the new form?

Thanks
Daniel
 
W

wuarhat

-----Original Message-----
When I want to add a record by opening a form with one or
more of the fields taken from a field on the first form
how do I do that? e.g. When the user clicks on the New
Appt button on frmPt it should open frmAppt for an
addition with the fApptPtID set to fPtID. I have been
tinkering with the following to no avail:

Private Sub btnNewAppt_Click()
'Opens a new appointment form for the current patient
DoCmd.OpenForm "frmAppt", acNormal, , "fApptPtID" = Me!
fPtID, acFormAdd
End Sub

Where am I going wrong? and can I make multiple fields go
to the new form? Do I use the args section to set values
in the new form?

Thanks
Daniel
.

This is a command button click event procedure that works
in Access 2000.

Private Sub create_appointment_record_Click()

'variable declarations

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset

'variable definitions
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset


With rst
.ActiveConnection = cnn
.CursorType = adOpenKeyset
.Open Source:="appointments",
LockType:=adLockOptimistic

' the preceding: "from .Open " should be one line
' appointmednts is a table name for appoints

End With

rst.AddNew Array("Date", "time", "customer"), Array(CStr
([appointment_date]), CStr([appointment_time]), CStr
([customer]))

'the preceding three lines should be one line
'date, time, customer are fields in the appointments table
'appointment_date, appointment_time, customer are the
'names of fields on the form

'unless the key field of the appointments table is
'an auto number tou might have to include that in each
'array also

rst.Close

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top