New record code not working

mafhobb

Registered User.
Local time
Today, 17:12
Joined
Feb 28, 2006
Messages
1,249
Hi Everyone.

I have a subform (call listing subform) that is on a form (contacts). This subform is shown as a continuous form. This form has "allowadditions" disabled. This subform is, of course, bound to a table.

To add data to this form/table, I have a button on the subform that opens an unbound form where I can enter the data. Then I click on a button that has the following code to get the data from this unbound form to the call listing subform.
Code:
Private Sub Add_Call_Click()
On Error GoTo err_Click

'Data conditioning
Me.SKUEntry.SetFocus
If Me.SKUEntry.Text = "" Then
    MsgBox "Please enter a SKU Number."
    Exit Sub
End If
Me.SubjectEntry.SetFocus
If Me.SubjectEntry.Text = "" Then
    MsgBox "Please enter a Subject."
    Exit Sub
End If
Me.StaffEntry.SetFocus
If Me.StaffEntry.Text = "" Then
    MsgBox "Please enter a Staff Name."
    Exit Sub
End If

'Allow additions to other form
Forms![Contacts]![Call Listing Subform].Form.AllowAdditions = Not Forms![Contacts]![Call Listing Subform].Form.AllowAdditions

'go to new record on other form
DoCmd.GoToRecord , , acNewRec

'Set focus and assign values
Me.SKUEntry.SetFocus
Forms![Contacts]![Call Listing Subform].Form![SKU] = Me.SKUEntry.Text
MsgBox "New SKU done"
Me.SubjectEntry.SetFocus
Forms![Contacts]![Call Listing Subform].Form![Subject] = Me.SubjectEntry.Text
MsgBox "New Subject done"
Me.StaffEntry.SetFocus
Forms![Contacts]![Call Listing Subform].Form![Staff] = Me.StaffEntry.Text
MsgBox "New Staff done"
Me.Details.SetFocus
If Me.Details.Text = "" Then
    MsgBox "No call details to enter"
Else
    Forms![Contacts]![Call Details Subform].Form![Notes] = Me.Details.Text
    MsgBox "Added call details"
End If

'Deny additions to other form
Forms![Contacts]![Call Listing Subform].Form.AllowAdditions = Not Forms![Contacts]![Call Listing Subform].Form.AllowAdditions

'Close this form
DoCmd.Close
Exit Sub

err_Click:
MsgBox Err.Description
Exit Sub
End Sub

The problem is that, as is, I get the error "cannot go to that record" when Access gets to "DoCmd.GoToRecord , , acNewRec", but if I take that line out, it tries to paste the new entry over an older one.

What am I missing

Thanks

Mafhobb
 
Perhaps you dont allow additions to you attached recordset?
Form Property: AllowAdditions = True

HTH:D
 
The default form value for "AllowAdditions" is set to "No", but the following code:
Code:
'Allow additions to other form
Forms![Contacts]![Call Listing Subform].Form.AllowAdditions = Not Forms![Contacts]![Call Listing Subform].Form.AllowAdditions
is supposed to toggle that to TRUE to allow the addition. Later in the code another line like this sets it back to "No"

If I get rid of the line
Code:
DoCmd.GoToRecord , , acNewRec
then I can see how the AllowAdditions property is getting set to "True", but the problem is that as the values are transferred from the unbound form to the subform, they do not go to these new record fields...instead, they edit the previous record....

Mafhobb
 
Maybe the problem is that this line
Code:
DoCmd.GoToRecord , , acNewRec
does not know what subform/table it is supposed to act upon???

How would I tell this line that it is the subform "call details subform" that it needs to act on?

Maybe it is the "calls" table it need to act on? How do I do that?

mafhobb
 
Well, I have tried everything I can think of...but to no avail. Absolutely ANY suggestion would be appreciated.

Mafhobb
 
I have added:
Code:
Forms![Contacts]![Call Listing Subform].SetFocus
before the Docmd line, but it does not seem to make a difference.

mafhobb
 
I have also tried the SendKeys method, but that did not work either
 
Two things for you-

1. you are never moving to a new record, so it is modifying the existing one.

2. Get rid of all of the Set Focus stuff. If you get rid of using the .Text part you don't need to set focus. Just remove the .Text part like this:

If Me.SKUEntry = "" Then


Then you don't need the Me.SKUEntry.SetFocus stuff and the same goes with ALL of it.

To move to a new record on the subform you can use:

Forms![Contacts]![Call Listing Subform].Form.Recordset.AddNew

and if the code we are talking about is on the main form where the subform is, you can shorten it to:

Me.[Call Listing Subform].Form.Recordset.AddNew
 
Yes, you are correct. This solves the new record problem and simplifies the code quite a bit. I am now having a different issues, which is the one I was trying to get rid of to begin with....This is that once the data is entered and the form closes to show the initial subform (call Listing subform), I get the error attached below... ContactID is listed in the subform as seen in the other jpeg.

Any idea what is happening?

m
 

Attachments

  • error2.JPG
    error2.JPG
    12.7 KB · Views: 134
  • Comment.JPG
    Comment.JPG
    42.3 KB · Views: 136
Your underlying table has the required propery set to True for the field in question. Remove this requirement and do the validation at form level.

David
 
Now I get this other error
 

Attachments

  • untitled.JPG
    untitled.JPG
    19.2 KB · Views: 127
I have attached the db. Maybe you guys have a better idea on how to fix this. The problems comes in after adding a call to the calls listing subform though the button above it.
 

Attachments

Users who are viewing this thread

Back
Top Bottom