OPEN FORM WITH NEW RECORD DISPLAYED

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

HOW DO I OPEN A FORM AND HAVE A NEW RECORD DISPLAYED FOR INPUT RATHER THAN PREVIOUS RECORDS THAT HAVE ALREADY BEEN FILLED OUT??
 
To only allow new records to be added, simply set the form's Data Entry
property to Yes.

If you want to open the existing record set, but default to the new record,
then add code to the form's OnOpen event such as...



Private Sub Form_Open(Cancel As Integer)
DoCmd.GoToRecord , , acNewRec
End Sub


Rick B




HOW DO I OPEN A FORM AND HAVE A NEW RECORD DISPLAYED FOR INPUT RATHER THAN
PREVIOUS RECORDS THAT HAVE ALREADY BEEN FILLED OUT??
 
I am seem to be having a problem I have never had before. (I most be doing something different.) I am trying to set up a button on one form to open another form in newrecord mode and carry I need it to carry accross the value that ties the records together. On the wizard I match the fields, but it doesn't seem to be working. ideas?
 
Hi Scott,

I don't know if you're even still needing this, but this is the code I use
in order to 'carry over' fields from one form to another:
I start by putting the following in the Form's 'On Current' Event:

Private Sub Form_Current()
If Me.NewRecord Then
Call SetAutoValues(Me)
Else
Call LockControls(Me)
End If
End Sub

which, if a New Record calls the following Module:

Sub SetAutoValues(frm As Form)
On Error GoTo SetAutoValues_err

' Set Automatic Values in each form in series
' Add as many fields as necessary (make sure each field has the same
name on EVERY form)
With frm
!id = Forms!fEnterPatientInfo!id
!ptin = Forms!fEnterPatientInfo!ptin
!site = Forms!fEnterPatientInfo!site
End With

SetAutoValues_err:
'MsgBox Err.Description
Resume Next

End Sub

or if it is NOT a New Record, and you want to 'Lock' already existing
records to prevent data changes while viewing them. This code basically
locks all the different types of controls that could be on a form, and gives
the option to NOT lock certain controls by setting the 'Tag' property of that
control. Here is that code:

Public Sub LockControls(frm As Form)
On Error Resume Next
Dim ctl As Control

For Each ctl In frm.Controls
With ctl

Select Case .ControlType
Case acTextBox
ctl.Locked = True

Case acComboBox
If ctl.Tag = 2 Then
ctl.Locked = False
Else
ctl.Locked = True
End If

Case acListBox
ctl.Locked = True

Case acCheckBox
ctl.Locked = True

Case acToggleButton
ctl.Locked = True

Case acCommandButton
If ctl.Tag = 2 Then
ctl.Enabled = False
Else
ctl.Enalbled = True
End If

Case acSubform
ctl.Locked = True

Case acOptionGroup
ctl.Locked = True

Case acOptionButton
ctl.Locked = True

End Select
End With
Next ctl
Set ctl = Nothing
Set frm = Nothing

End Sub

HTH, Patrick
 
Back
Top