Subform grayed out when adding new record

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

Guest

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
 
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
 
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
 
Try and refresh the form, before openning a new record

Try to refresh the form after you add a new record



lngID = rs.Fields("ID").Value
' Position to the new record
Me.Requery
DoCmd.ApplyFilter , "[ID]=" & lngID
--
I hope that helped
Good luck


mscertified said:
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 found out that the allowadditions, allowdeletions and allowedits properties
are being set to false. Access must be doing it because I am not. If I set
them back to true in my tab_change event, it all works fine. But I'd sure
like to know why this is happening.
I think it must be something to do with the record I was positioned on
previously because the New button works whan I click it from a current record.

Ofer said:
Try and refresh the form, before openning a new record

Try to refresh the form after you add a new record



lngID = rs.Fields("ID").Value
' Position to the new record
Me.Requery
DoCmd.ApplyFilter , "[ID]=" & lngID
--
I hope that helped
Good luck


mscertified said:
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
 
I know of one reason why that can happen,
When you run the form, and you set this properties to false using code, if
you create a code break and then you save the code while the form is running,
you actually save the form with the properties you set using the code.
So it is better not to save the code of a form, while the form is running,
exit the form and then make the changes
--
I hope that helped
Good luck


mscertified said:
I found out that the allowadditions, allowdeletions and allowedits properties
are being set to false. Access must be doing it because I am not. If I set
them back to true in my tab_change event, it all works fine. But I'd sure
like to know why this is happening.
I think it must be something to do with the record I was positioned on
previously because the New button works whan I click it from a current record.

Ofer said:
Try and refresh the form, before openning a new record

Try to refresh the form after you add a new record



lngID = rs.Fields("ID").Value
' Position to the new record
Me.Requery
DoCmd.ApplyFilter , "[ID]=" & lngID
--
I hope that helped
Good luck


mscertified said:
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


:

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
 
Back
Top