Error - Udate or CancelUpdate without Addnew or Edit

K

Kurt Monroe

I have a Help-Desk form that displays rows of data (called "problems"). The
users want to double-click on a row (Problem to them) and open the form that
shows the many details of that one specific Problem. I can do that by
opening the EditProblem form this way:

stLinkCriteria = "[Ticket Number] = Me![Ticket Number]
DoCmd.OpenForm stDocName, , , stLinkCriteria

That allows them to see the details of the problem just fine.

But then they wanted to remain in the EditProblem form and be able to
navigate through the Problems that they saw on the first form, while they are
in the EditProblem form, instead of having to close the EditProblem form and
double-click on the next Problem in the first form, which then takes them
back to the EditProblems form.

So, now when they double-click on a row in the first form, I load up a
"SelectedProblems" table with the Key ([Ticket Number]) from the currently
displayed rows, and then I open up the EditProblem form with this:

stLinkCriteria = "[Ticket Number] in (select [ticket number] from
SelectedProblems)"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Then I navigate to the desired ticket with this:

'navigate to the record
Set Frm = Forms(frmNm$)
Set rs = Frm.RecordsetClone
varTicketNumber = Me!Current_ticket
crit$ = "[Ticket Number]= " & varTicketNumber
rs.FindFirst crit$
Frm.Bookmark = rs.Bookmark
Frm.[Ticket Number].SetFocus
Set rs = Nothing
Set Frm = Nothing

But then, sometimes, very intermittently, I can't find a pattern to it,
while in the EditProblem form, they will sometimes get this error:

"update or cancelupdate without Addnew or Edit"

This EditProblem form is very complex with lots of subforms and updating and
adding. I cannnot figure out what to do at this point.

Is there another way to allow navigating through the records in the
EditProblems form?

I don't keep the "calling form" open, I close it whenever they double-click
and open the EditProblem form.

I think the RecordsetClone is giving me this problem. Any suggestions?

Thanks,
 
P

Peter Martin

I don't see any relevant problem with this code, though I always check for
..nomatch after a .findfirst. SUggest you code search the for .addnew and
..edit projectwide & concentrate on your subforms. Probably you have
something on a subform oncurrent or beforeupdate/insert that goes wonky when
a user slides into a new detail record.

I use another way successfuly. THe main form (with the list) has a listbox
with filtering controls at the top which build a where clause (IN
(SELECT...)). Whenever that gets built it applies the filter to the edit
form if open and sets the current record. This allows the edit form to have
an updateable query even when the listbox hasnt' (groupby's, max's etc).
Code in main and edit oncurrent resyncs one to the other - nicely, as you
roll through the edit form the listbox selection changes in sync. Havent got
round to scrolling the listbox to keep up yet - might work on it next visit
to the oracle at lebans. New records are created on the edit form, which
refreshes the listbox after adding at the bottom. Multiselecting in listbox
is used for bulk stuff (printing..) but doesn't refresh edit form. Also
saves the forms location and size for each user.

Good luck.

Kurt Monroe said:
I have a Help-Desk form that displays rows of data (called "problems"). The
users want to double-click on a row (Problem to them) and open the form that
shows the many details of that one specific Problem. I can do that by
opening the EditProblem form this way:

stLinkCriteria = "[Ticket Number] = Me![Ticket Number]
DoCmd.OpenForm stDocName, , , stLinkCriteria

That allows them to see the details of the problem just fine.

But then they wanted to remain in the EditProblem form and be able to
navigate through the Problems that they saw on the first form, while they are
in the EditProblem form, instead of having to close the EditProblem form and
double-click on the next Problem in the first form, which then takes them
back to the EditProblems form.

So, now when they double-click on a row in the first form, I load up a
"SelectedProblems" table with the Key ([Ticket Number]) from the currently
displayed rows, and then I open up the EditProblem form with this:

stLinkCriteria = "[Ticket Number] in (select [ticket number] from
SelectedProblems)"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Then I navigate to the desired ticket with this:

'navigate to the record
Set Frm = Forms(frmNm$)
Set rs = Frm.RecordsetClone
varTicketNumber = Me!Current_ticket
crit$ = "[Ticket Number]= " & varTicketNumber
rs.FindFirst crit$
Frm.Bookmark = rs.Bookmark
Frm.[Ticket Number].SetFocus
Set rs = Nothing
Set Frm = Nothing

But then, sometimes, very intermittently, I can't find a pattern to it,
while in the EditProblem form, they will sometimes get this error:

"update or cancelupdate without Addnew or Edit"

This EditProblem form is very complex with lots of subforms and updating and
adding. I cannnot figure out what to do at this point.

Is there another way to allow navigating through the records in the
EditProblems form?

I don't keep the "calling form" open, I close it whenever they double-click
and open the EditProblem form.

I think the RecordsetClone is giving me this problem. Any suggestions?

Thanks,
 
S

Stephen Lebans

You can simulate the standard VB ListBox TopIndex prop here:
http://www.lebans.com/List_Combo.htm#ScrollListbox
Scroll a ListBox to a specific row. Emulates the VB ListBox TopIndex
property. You can alter the code to easily have the selected row display
as the first or last row as well. The example code is placed behind a
Command Button.

' *** CODE START
Private Sub cmdListIndex_Click()
On Error GoTo Err_cmdListIndex_Click

' Always make NumRows an odd number
' if you want selected Row to be in the
' middle of the ListBox.

' NumRows is the number of completely visible rows in the ListBox Const
NumRows = 7
' Row we want displayed in middle of ListBox.
Dim intDesiredRow As Integer

' Arbitrarily select the 24th row.
intDesiredRow = 24
' ListBox must have the Focus
Me.List2.SetFocus
' Force ListBox to start from the top
Me.List2.ListIndex = 1

' Force the Scroll offset we desire
Me.List2.ListIndex = intDesiredRow + (NumRows / 2)
' Now select the row without further scrolling
Me.List2.ListIndex = intDesiredRow

Exit_cmdListIndex_Click:
Exit Sub

Err_cmdListIndex_Click:
MsgBox Err.Description
Resume Exit_cmdListIndex_Click

End Sub
' ***CODE END


Method #2

Here's the code to force a ListBox to Scroll to a specific row. I put it
behind a Command Button Named Customer, you can obviously do
whatever you want. Really should be a Class Wrapper for a ListBox to
expose a TopIndex property like VB ListBoxes.

' ***CODE START
'Place this code in the General Declarations of your Form
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long

Private Declare Function GetFocus Lib "user32" () As Long

' Windows Message Constant
Private Const WM_VSCROLL = &H115
' Scroll Bar Commands
Private Const SB_THUMBPOSITION = 4
' Code end for General Declarations


' Code for Control's Click Event
Private Sub Customer_Click()

Dim hWndSB As Long
Dim lngRet As Long
Dim lngIndex As Long
Dim LngThumb As Long

' You will get lngIndex value from the user or whatever.
' For now I'm just setting it to arbitrary Number
lngIndex = 45

' SetFocus to our listBox so that we can
' get its hWnd
Me.List2.SetFocus
hWndSB = GetFocus

' Set the window's ScrollBar position
LngThumb = MakeDWord(SB_THUMBPOSITION, CInt(LngIndex))
lngRet = SendMessage(hWndSB, WM_VSCROLL, LngThumb, 0&)

End Sub

' Here's the MakeDWord function from the MS KB
Function MakeDWord(loword As Integer, hiword As Integer) As Long
MakeDWord = (hiword * &H10000) Or (loword And &HFFFF&) End Function
'***END CODE




--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


Peter Martin said:
I don't see any relevant problem with this code, though I always check for
.nomatch after a .findfirst. SUggest you code search the for .addnew and
.edit projectwide & concentrate on your subforms. Probably you have
something on a subform oncurrent or beforeupdate/insert that goes wonky when
a user slides into a new detail record.

I use another way successfuly. THe main form (with the list) has a listbox
with filtering controls at the top which build a where clause (IN
(SELECT...)). Whenever that gets built it applies the filter to the edit
form if open and sets the current record. This allows the edit form to have
an updateable query even when the listbox hasnt' (groupby's, max's etc).
Code in main and edit oncurrent resyncs one to the other - nicely, as you
roll through the edit form the listbox selection changes in sync. Havent got
round to scrolling the listbox to keep up yet - might work on it next visit
to the oracle at lebans. New records are created on the edit form, which
refreshes the listbox after adding at the bottom. Multiselecting in listbox
is used for bulk stuff (printing..) but doesn't refresh edit form. Also
saves the forms location and size for each user.

Good luck.

Kurt Monroe said:
I have a Help-Desk form that displays rows of data (called "problems"). The
users want to double-click on a row (Problem to them) and open the form that
shows the many details of that one specific Problem. I can do that by
opening the EditProblem form this way:

stLinkCriteria = "[Ticket Number] = Me![Ticket Number]
DoCmd.OpenForm stDocName, , , stLinkCriteria

That allows them to see the details of the problem just fine.

But then they wanted to remain in the EditProblem form and be able to
navigate through the Problems that they saw on the first form, while they are
in the EditProblem form, instead of having to close the EditProblem form and
double-click on the next Problem in the first form, which then takes them
back to the EditProblems form.

So, now when they double-click on a row in the first form, I load up a
"SelectedProblems" table with the Key ([Ticket Number]) from the currently
displayed rows, and then I open up the EditProblem form with this:

stLinkCriteria = "[Ticket Number] in (select [ticket number] from
SelectedProblems)"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Then I navigate to the desired ticket with this:

'navigate to the record
Set Frm = Forms(frmNm$)
Set rs = Frm.RecordsetClone
varTicketNumber = Me!Current_ticket
crit$ = "[Ticket Number]= " & varTicketNumber
rs.FindFirst crit$
Frm.Bookmark = rs.Bookmark
Frm.[Ticket Number].SetFocus
Set rs = Nothing
Set Frm = Nothing

But then, sometimes, very intermittently, I can't find a pattern to it,
while in the EditProblem form, they will sometimes get this error:

"update or cancelupdate without Addnew or Edit"

This EditProblem form is very complex with lots of subforms and updating and
adding. I cannnot figure out what to do at this point.

Is there another way to allow navigating through the records in the
EditProblems form?

I don't keep the "calling form" open, I close it whenever they double-click
and open the EditProblem form.

I think the RecordsetClone is giving me this problem. Any suggestions?

Thanks,
 

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