Link to home
Start Free TrialLog in
Avatar of intern1
intern1

asked on

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

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?
Avatar of intern1
intern1

ASKER

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.
Avatar of rockiroads
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




Avatar of intern1

ASKER

I believe, at least in Access, If you have column headers they count as the first row, but i will double check.
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
Have u tried creating a seperate rowsource

supposed to say

Have u tried creating a seperate recordset
Avatar of intern1

ASKER

I changed it to lstParts.rowsource = sSQL

It still gives me that lock error
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

Avatar of intern1

ASKER

doesn't work.  I also tried putting the recordset back to the listbox and used dbOpenSnapShot as the type. That didn't work either
Avatar of intern1

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of intern1

ASKER

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
whats the alternative, a subform perhaps?