The code is pretty long and very involved. Also I found out that sometimes it
works and sometimes it does not. I have no idea what triggers this problem
but it's always after hitting the New button. The subform works fine when
editing an existing record and you can edit, delete or insert rows. Here is
the New button code.
Private Sub butNew_Click()
' Add a new Issue with default fields
On Error GoTo ER
Dim rs As New ADODB.Recordset
Dim lngID As Long
Dim dteNow As Date
' Prevent save of invalid record
If Not CheckFields() Then Exit Sub
dteNow = Now()
' Add a new record with a unique datestamp
rs.Open "SELECT * FROM tblIssues WHERE ID = 0", _
CurrentProject.Connection, adOpenForwardOnly, adLockOptimistic
rs.AddNew
rs.Fields("StatusID").Value = 1
rs.Fields("Created").Value = dteNow
rs.Update
lngID = rs.Fields("ID").Value
' Position to the new record
DoCmd.ApplyFilter , "[ID]=" & lngID
Me!Tabs = 0
' Set defaults below
Me!Issue.SetFocus
Me!Created = dteNow
rs.Close
Call SetMode("New")
EX:
Set rs = Nothing
Exit Sub
ER:
MsgBox Err.Description, vbOKOnly, "butNew_Click"
End Sub
Public Function SetMode(Mode As String)
'Set form capability properties
On Error GoTo ER
'No need for navigation buttons since viewing one record at a time
Me.NavigationButtons = False
Me!Issue.SetFocus
Select Case Mode
Case "New"
Me.AllowEdits = True
Me.AllowDeletions = False
Me!butSave.Enabled = True
Me!butSave.SetFocus
Me!butNew.Enabled = False
Me!butDelete.Enabled = True
Me!butFirst.Enabled = False
Me!butPrev.Enabled = False
Me!butNext.Enabled = False
Me!butLast.Enabled = False
Me!Issue.SetFocus
Case "Edit"
Me.AllowEdits = True
Me.AllowDeletions = False
Me!butNew.Enabled = True
Me!butSave.Enabled = False
Me!butDelete.Enabled = True
Me!butFirst.Enabled = True
Me!butPrev.Enabled = True
Me!butNext.Enabled = True
Me!butLast.Enabled = True
Me!Issue.SetFocus
Case "Prot"
Me.AllowEdits = False
Me.AllowDeletions = False
Me!butNew.Enabled = False
Me!butSave.Enabled = False
Me!butDelete.Enabled = False
Me!butFirst.Enabled = True
Me!butPrev.Enabled = True
Me!butNext.Enabled = True
Me!butLast.Enabled = True
Me!butNext.SetFocus
End Select
EX:
Exit Function
ER:
MsgBox Err.Description, vbOKOnly, "SetMode"
End Function
Ofer said:
If the subform is bound to a table or a query, check if you can add new
records to them directly.
e.g a table on sql server with no keys on it, will allow you to edit, but
not add new records.
Does the AllowAdditions Property of te sub form set to yes?
If that is not the case, can you post the code you are using fin the command
to add new records
--
I hope that helped
Good luck
:
I have a form with a tabbed control containing a subform. There is a 'New'
button on the form that creates a new record (via INSERT) and blanks out all
entry fields. When I click New and then go to the tab with the subform, the
entire subform is grayed out and I cannot enter any data. When editing
existing records, the subform works fine. Any ideas?
Thanks - david