I have a form that when the user double-clicks a listbox, the record is retrived and placed on the form for editing. I keep getting the runtime error when I try to clear the form. The code is below.
The code is used to clear textboxes on a form. The control in question is a listbox. This is a project that I originally started in Excel and realized that it would better to use Access although, I've never programmed in it before. The SetFocus is in there because I got an error that I couldn't change properties on a control unless it had focus. Seemed a bit strange to me. I'm beginning to wonder if the file isn't corrupted some how.I have not tried to change each indiviual textbox but that would be the next step. I'm hoping that someone has an idea of what's going on. It seems to me that there is no reason why this code shouldn't run. This logic has run on every MS product I've ever programmed in.
Another strange thing is the name of the control in the error message is Maintenance Log. It says "Run-time 2110 Maintenance Log Can't move focus to the control txtDescription. txtDescription is on the form but there is no control named Maintenance Log. The listbox is named lstMaintLog. I did change it from lstMaintenanceLog after I wired the double-click event to it. I changed the event name and recreated it so, there shouldn't be any problem there.
Code:
'Traverses form and clears contents from textboxes
For Each cCont In Me.Controls
If TypeName(cCont) = "TextBox" Then
cCont.SetFocus
cCont.Text = ""
End If
Next cCont
The code is used to clear textboxes on a form. The control in question is a listbox. This is a project that I originally started in Excel and realized that it would better to use Access although, I've never programmed in it before. The SetFocus is in there because I got an error that I couldn't change properties on a control unless it had focus. Seemed a bit strange to me. I'm beginning to wonder if the file isn't corrupted some how.I have not tried to change each indiviual textbox but that would be the next step. I'm hoping that someone has an idea of what's going on. It seems to me that there is no reason why this code shouldn't run. This logic has run on every MS product I've ever programmed in.
Another strange thing is the name of the control in the error message is Maintenance Log. It says "Run-time 2110 Maintenance Log Can't move focus to the control txtDescription. txtDescription is on the form but there is no control named Maintenance Log. The listbox is named lstMaintLog. I did change it from lstMaintenanceLog after I wired the double-click event to it. I changed the event name and recreated it so, there shouldn't be any problem there.