Solved

You can't lock a control while it has unsaved changes

Posted on 2006-06-27
14
635 Views
Last Modified: 2009-12-16
Private Sub btnCalc_Click()
    Dim blnOK As Boolean
   
    blnOK = checkErrors
   
    If blnOK Then
        calculatePrice
        lblPrice.Caption = FormatCurrency(totalPrice)
        lblCost.Caption = FormatCurrency(totalCost)
        lblHours.Caption = totalHours
        Set lstPart.Recordset = rsPart
       
        highlightUsed
        lstPart.Locked = True
       
        blnQuoteGiven = True
    End If
   
   
   
End Sub

Public Sub highlightUsed()
    'highlights the row in the listbox that has the price that was used for the estimate
   
    Dim i As Integer
    For i = 1 To lstPart.ListCount
        If lstPart.Column(1, i) = rsPart!WAREHOUSE Then
            lstPart.Selected(i) = True
            Exit Sub
        End If
    Next
End Sub

"You can't lock a control while it has unsaved changes"
Why do i get this error, and how can i fix it?
0
Comment
Question by:intern1
  • 6
  • 6
14 Comments
 

Author Comment

by:intern1
ID: 16995136
I'm trying to highlight the row in the listbox which has a value that has a certain value in it and then lock it so that it cannot be unselected.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16995613
just to note, listbox entries start subscript start from zero

it should be for

for i = 0 to lstPart.ListCount-1


but not seen your error with regards to a listbox before




0
 

Author Comment

by:intern1
ID: 16995627
I believe, at least in Access, If you have column headers they count as the first row, but i will double check.
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 65

Expert Comment

by:rockiroads
ID: 16995757
ok, I didnt realise u had column headers, in that case then yes, u start from 1

What is rsPart, is that rs anything to do with current form?
Have u tried creating a seperate rowsource, perhaps set rowsource using SQL instead
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16995761
Have u tried creating a seperate rowsource

supposed to say

Have u tried creating a seperate recordset
0
 

Author Comment

by:intern1
ID: 16996167
I changed it to lstParts.rowsource = sSQL

It still gives me that lock error
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16996243
Hmmm, I wonder if its changes in the form that your in, hence the error message
Though it dont make sense why it complains about it when u try to lock a listbox
Thats MS Access for ya


try one of two things

Me.Requery

or

Me.Dirty = False

before u lock the listbox

0
 

Author Comment

by:intern1
ID: 16996339
doesn't work.  I also tried putting the recordset back to the listbox and used dbOpenSnapShot as the type. That didn't work either
0
 

Author Comment

by:intern1
ID: 16996400
I made a temporary fix.  I'm storing the index i want selected in a module level variable and using the listbox click event to reselect it everytime a different list item gets clicked on.

But i'm still open to a real fix
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 16996415
I thought about that also, but I thought u wouldnt like that idea as its a hack

what happens if u disable the listbox instead of locking it, does that make a difference?
0
 

Author Comment

by:intern1
ID: 16996678
Disabling it works, but poses a problem if i want to allow them to scroll still.  I guess Lock would do the same thing? so i'll just have to make sure that i have the listbox big enough to see all possible items if i do that
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16996731
whats the alternative, a subform perhaps?
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hit enter key to run macro 13 23
Restoring a form to its default settings 3 26
VBA to copy the database back end to a new database file. 3 34
backup programme - VBA 3 22
This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now