Need help with coding runtime error.

G

Guest

Hi all:
I am modifing a database created by someone else have have run into the
following error:

"Run-Time error: 2046 - The command or action "RecordGoToNew" isn't
available now."

When I click on the debug screen the following line of code is high-lighted"
DoCmd.RunCommand acCmdRecordsGoToNew

Can anyone please explain to me what the problem is and offer a possible
solution? Any help would be greatly appreciated.

I have inluded the entire code for the form's load event below.

Thanks,
FatMan

Private Sub Form_Load()
Dim db As Database
Dim rs As Recordset
Dim rs2 As Recordset
Dim rs3 As Recordset
Dim i As Integer
Dim frm As Form
'Dim i As Integer
Dim tbc As Control, pge As Page
Dim ctl As Control

Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT tblServAreaName.*,
tblServAreaName.snInactive " _
& "FROM tblServAreaName " _
& "WHERE (((tblServAreaName.snInactive)=No));")
Set frm = Forms!frmCustCare
' Return reference to tab control.
Set tbc = frm!TabCtrl
' Return reference to currently selected page.
Set pge = tbc.Pages(tbc.Value)

rs.MoveFirst
i = 1

Do While Not rs.EOF And i < 16
Me("sbf" & i).SourceObject = "sbfTaskNotes"
Me("Page" & i).Caption = rs!snName
Me("CurSANameID" & i) = rs!snServAreaNameID
Me("Page" & i).Visible = True
rs.MoveNext
i = i + 1
Loop

If i > 16 Then
MsgBox "There are more than 15 Sevice areas to diplay." & vbCrLf &
"Close Service areas that are no longer active."
End If

Do While i < 16
Me("Page" & i).Visible = False
i = i + 1
Loop

rs.MoveFirst
If OpenArgs = "Modify" Then

If Forms!frmContSum!ccFollowUp Then
Call OpenFolUp
Else
Set rs3 = db.OpenRecordset("SELECT tblCustCare.ccCustCareID,
tblCustCare.SANameID, tblCustCare.ContactID, tblCustCare.ccContDate,
tblCustCare.ccContactType, tblCustCare.ccFollowUp, tblTasks.tsType,
tblTasks.tsMainNote, tblTasks.tsNoteID, tblContacts.ctCompanyName,
tblContacts.ctFirstName1, tblContacts.ctLastName1 " _
& "FROM tblContacts INNER JOIN (tblCustCare INNER JOIN tblTasks
ON tblCustCare.ccCustCareID = tblTasks.CustCareID) ON tblContacts.ctContactID
= tblCustCare.ContactID " _
& "WHERE (((tblCustCare.ccCustCareID)=" &
[Forms]![frmContSum]![ccCustCareID] & "));")
frm.RecordsetClone.FindFirst "[ccCustCareID] = " & rs3!ccCustCareID
frm.Bookmark = frm.RecordsetClone.Bookmark

Set rs = db.OpenRecordset("SELECT tblServAreaName.* FROM
tblServAreaName;")
rs.MoveFirst
frm!CurContID = Forms!frmContSum!ContactID
Set rs2 = db.OpenRecordset("tblTasks", dbOpenDynaset)
rs2.FindFirst "CustCareID = " & rs3!ccCustCareID
frm!CurNoteID = rs2!tsNoteID
frm!SANameID = rs2!SANameID
rs.MoveFirst
i = 1
Do While Not rs.EOF And i < 16
If rs!snServAreaNameID = frm!SANameID Then
If pge.Name = frm("Page" & i).Name Then
Else
gbOK = False 'If current tab is not the one that is
being entered into contact TabCtrl change is activated
End If 'and do not check for
TabCtrl change
frm("Page" & i).SetFocus
frm!sbfName = "sbf" & i
Set gCtrl = frm.Controls("sbf" & i)
frm!CurSANameID = rs!snServAreaNameID
frm("sbf" & i).Requery
gCtrl!sbfTaskList.Requery
gCtrl!sbfTaskList!cmbTask.Requery
gCtrl!sbfCustNote.Requery
If rs3!ccFollowUp Then
Forms!frmCustCare!lblContType.Caption = "Follow Up
Contact"
Forms!frmCustCare!lblContType.BackColor = 16776960
Else
Forms!frmCustCare!lblContType.Caption = "Contact"
Forms!frmCustCare!lblContType.BackColor = 11599305
End If
End If

rs.MoveNext
i = i + 1
Loop
If IsNull(rs3!ctLastName1) Then
Me!OperatingAs = rs3!ctCompanyName
Else
Me!OperatingAs = rs3!ctLastName1 & ", " & rs3!ctFirstName1
End If

frm!cmbInitiatBy.SetFocus
End If
Else
Set rs3 = db.OpenRecordset("SELECT tblContacts.* " _
& "FROM tblContacts " _
& "WHERE (((tblContacts.ctContactID)= " & OpenArgs & "));")
Me!CurContID = OpenArgs
If IsNull(rs3!ctLastName1) Then
Me!OperatingAs = rs3!ctCompanyName
Else
Me!OperatingAs = rs3!ctLastName1 & ", " & rs3!ctFirstName1
End If

Me!CurNoteID = 0
Me!CurSANameID = rs!snServAreaNameID
Me!sbfName = "sbf1"

Set rs2 = db.OpenRecordset("tblTasks", dbOpenDynaset)
If rs2.RecordCount > 0 Then
DoCmd.RunCommand acCmdRecordsGoToNew
End If

Set gCtrl = Me.Controls("sbf1")
gCtrl!sbfTaskList.Requery
gCtrl!sbfTaskList!cmbTask.Requery
frm!cmbInitiatBy.SetFocus
End If

End Sub
 
V

Van T. Dinh

The code attempts to make a NewRecord (in the Form buffer only) the
CurrentRecord of the Form ready for data entry by the user.

There are a number of possible reasons that stop the above process. The
nore common reasons are:

1. The RecordSource of the Form is not updatable. Check whether the Query /
SQL being used as the RecordSource for the Form returns an updatable
Recordset.

2. The Form's Property "AllowAdditions" is set to No / False.

3. The Form's Property "Recordset" is set to "Snapshop".

Check these Properties in the DesignView of the Form and code since it is
possible to change the Property values in code.

--
HTH
Van T. Dinh
MVP (Access)



FatMan said:
Hi all:
I am modifing a database created by someone else have have run into the
following error:

"Run-Time error: 2046 - The command or action "RecordGoToNew" isn't
available now."

When I click on the debug screen the following line of code is
high-lighted"
DoCmd.RunCommand acCmdRecordsGoToNew

Can anyone please explain to me what the problem is and offer a possible
solution? Any help would be greatly appreciated.

I have inluded the entire code for the form's load event below.

Thanks,
FatMan

Private Sub Form_Load()
Dim db As Database
Dim rs As Recordset
Dim rs2 As Recordset
Dim rs3 As Recordset
Dim i As Integer
Dim frm As Form
'Dim i As Integer
Dim tbc As Control, pge As Page
Dim ctl As Control

Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT tblServAreaName.*,
tblServAreaName.snInactive " _
& "FROM tblServAreaName " _
& "WHERE (((tblServAreaName.snInactive)=No));")
Set frm = Forms!frmCustCare
' Return reference to tab control.
Set tbc = frm!TabCtrl
' Return reference to currently selected page.
Set pge = tbc.Pages(tbc.Value)

rs.MoveFirst
i = 1

Do While Not rs.EOF And i < 16
Me("sbf" & i).SourceObject = "sbfTaskNotes"
Me("Page" & i).Caption = rs!snName
Me("CurSANameID" & i) = rs!snServAreaNameID
Me("Page" & i).Visible = True
rs.MoveNext
i = i + 1
Loop

If i > 16 Then
MsgBox "There are more than 15 Sevice areas to diplay." & vbCrLf &
"Close Service areas that are no longer active."
End If

Do While i < 16
Me("Page" & i).Visible = False
i = i + 1
Loop

rs.MoveFirst
If OpenArgs = "Modify" Then

If Forms!frmContSum!ccFollowUp Then
Call OpenFolUp
Else
Set rs3 = db.OpenRecordset("SELECT tblCustCare.ccCustCareID,
tblCustCare.SANameID, tblCustCare.ContactID, tblCustCare.ccContDate,
tblCustCare.ccContactType, tblCustCare.ccFollowUp, tblTasks.tsType,
tblTasks.tsMainNote, tblTasks.tsNoteID, tblContacts.ctCompanyName,
tblContacts.ctFirstName1, tblContacts.ctLastName1 " _
& "FROM tblContacts INNER JOIN (tblCustCare INNER JOIN tblTasks
ON tblCustCare.ccCustCareID = tblTasks.CustCareID) ON
tblContacts.ctContactID
= tblCustCare.ContactID " _
& "WHERE (((tblCustCare.ccCustCareID)=" &
[Forms]![frmContSum]![ccCustCareID] & "));")
frm.RecordsetClone.FindFirst "[ccCustCareID] = " & rs3!ccCustCareID
frm.Bookmark = frm.RecordsetClone.Bookmark

Set rs = db.OpenRecordset("SELECT tblServAreaName.* FROM
tblServAreaName;")
rs.MoveFirst
frm!CurContID = Forms!frmContSum!ContactID
Set rs2 = db.OpenRecordset("tblTasks", dbOpenDynaset)
rs2.FindFirst "CustCareID = " & rs3!ccCustCareID
frm!CurNoteID = rs2!tsNoteID
frm!SANameID = rs2!SANameID
rs.MoveFirst
i = 1
Do While Not rs.EOF And i < 16
If rs!snServAreaNameID = frm!SANameID Then
If pge.Name = frm("Page" & i).Name Then
Else
gbOK = False 'If current tab is not the one that is
being entered into contact TabCtrl change is activated
End If 'and do not check for
TabCtrl change
frm("Page" & i).SetFocus
frm!sbfName = "sbf" & i
Set gCtrl = frm.Controls("sbf" & i)
frm!CurSANameID = rs!snServAreaNameID
frm("sbf" & i).Requery
gCtrl!sbfTaskList.Requery
gCtrl!sbfTaskList!cmbTask.Requery
gCtrl!sbfCustNote.Requery
If rs3!ccFollowUp Then
Forms!frmCustCare!lblContType.Caption = "Follow Up
Contact"
Forms!frmCustCare!lblContType.BackColor = 16776960
Else
Forms!frmCustCare!lblContType.Caption = "Contact"
Forms!frmCustCare!lblContType.BackColor = 11599305
End If
End If

rs.MoveNext
i = i + 1
Loop
If IsNull(rs3!ctLastName1) Then
Me!OperatingAs = rs3!ctCompanyName
Else
Me!OperatingAs = rs3!ctLastName1 & ", " & rs3!ctFirstName1
End If

frm!cmbInitiatBy.SetFocus
End If
Else
Set rs3 = db.OpenRecordset("SELECT tblContacts.* " _
& "FROM tblContacts " _
& "WHERE (((tblContacts.ctContactID)= " & OpenArgs & "));")
Me!CurContID = OpenArgs
If IsNull(rs3!ctLastName1) Then
Me!OperatingAs = rs3!ctCompanyName
Else
Me!OperatingAs = rs3!ctLastName1 & ", " & rs3!ctFirstName1
End If

Me!CurNoteID = 0
Me!CurSANameID = rs!snServAreaNameID
Me!sbfName = "sbf1"

Set rs2 = db.OpenRecordset("tblTasks", dbOpenDynaset)
If rs2.RecordCount > 0 Then
DoCmd.RunCommand acCmdRecordsGoToNew
End If

Set gCtrl = Me.Controls("sbf1")
gCtrl!sbfTaskList.Requery
gCtrl!sbfTaskList!cmbTask.Requery
frm!cmbInitiatBy.SetFocus
End If

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