Please help with code and ability to edit records on form (1 Viewer)

slharman1

Member
Local time
Today, 12:58
Joined
Mar 8, 2021
Messages
467
I have two similar forms based on similar data from two different tables. They are continuous forms with unbound text boxes in the header of the forms to align with the fields shown in form. When I type in the unbound text box it filters the form. The problem is this - on one form if I type something not in the list, I can back space in the unbound txtcontrol, on the other form, it gives me an error and says "You can't reference a property or method for a control unless it has the focus" I can't figure out the difference. Also the form I can backspace in the unbound control will let me edit the records in that form, the form that gives the error will not let me edit records. I can't figure out what I did to not allow the records to be edited, but I'm sure I did it when I created the form but as a newb i didn't document it.
All of the properties are the same for each form.
Here is the code for the form with control that works:

Code:
Private Sub txtDescFilter_Change()
Dim sText As String
Dim strFilter As String
    On Error GoTo ErrHandler
   sText = Me!txtDescFilter.Text
   If sText <> "" Then
        strFilter = "[Description] Like '*" & sText & "*'"
        Me.Filter = strFilter
        Me.FilterOn = True
    Else
        Me.Filter = ""
        Me.FilterOn = False
    End If
    With Me.txtDescFilter
        .SetFocus
        .Value = sText
        .SelStart = Len(sText)
        .SelLength = 0
    End With
    Exit Sub
ErrHandler:
    MsgBox Err.Description, vbExclamation
    'MsgBox ("That text is not in the list")
    'Me.Requery
   
End Sub

Here is the code for the form that gives the error:

Code:
Private Sub txtJobNameFilter_Change()

Dim sText As String
Dim strFilter As String
    On Error GoTo ErrHandler
   sText = Me!txtJobNameFilter.Text
   If sText <> "" Then
        strFilter = "[JobName] Like '*" & sText & "*'"
        Me.Filter = strFilter
        Me.FilterOn = True
    Else
        Me.Filter = ""
        Me.FilterOn = False
    End If
    With Me.txtJobNameFilter
        .SetFocus
        .Value = sText
        .SelStart = Len(sText)
        .SelLength = 0
    End With
    Exit Sub
ErrHandler:
    MsgBox Err.Description, vbExclamation
    'MsgBox ("That text is not in the list")
    'Me.Requery

End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:58
Joined
Oct 29, 2018
Messages
21,358
Hi. Wouldn't it be simpler if you could post a sample db, so we can examine both forms? Also, have you tried simply copying the first form that works and replace the second form with that copy?
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:58
Joined
Sep 21, 2011
Messages
14,045
AGAIN, on which line does that error occur?
Walk through your code line by line, after setting a breakpoint.
 

slharman1

Member
Local time
Today, 12:58
Joined
Mar 8, 2021
Messages
467
Hi. Wouldn't it be simpler if you could post a sample db, so we can examine both forms? Also, have you tried simply copying the first form that works and replace the second form with that copy?
What is the simplest way to delete a bunch of records out my database because I can’t post the information about my customers and projects. I don’t want to send a db with a bunch of orphaned records.
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:58
Joined
Sep 21, 2011
Messages
14,045
You just don’t get it gasman, the codes are identical.
Yes, they appear identical, but if it was me, I would do what I suggested. Walking the code finds what I call the silly/stupid errors.
So many times people here say things are the same when they are not. :(
I'll bow out now, as I am unable to help, and theDBguys suggestion of a sample would be best, as he will find your error.
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 10:58
Joined
Oct 29, 2018
Messages
21,358
What is the simplest way to delete a bunch of records out my database because I can’t post the information about my customers and projects. I don’t want to send a db with a bunch of orphaned records.
Export your tables to a new database and select Structure Only.

PS. However, please add some test data to help us understand how it's supposed to work. Thanks.
 

slharman1

Member
Local time
Today, 12:58
Joined
Mar 8, 2021
Messages
467
Hi. Wouldn't it be simpler if you could post a sample db, so we can examine both forms? Also, have you tried simply copying the first form that works and replace the second form with that copy?
DBGuy,
When you open the FE, click on Estimates on the switchboard and type in the search boxes at the top, everything works as it should.
Then go to orders and try to type into one of the search boxes at the top, if you type something that is not on the list, the error occurs.
Thanks for the help.
 

Attachments

  • DB1.accdb
    4.9 MB · Views: 475
  • DB1_be.accdb
    4.9 MB · Views: 304

slharman1

Member
Local time
Today, 12:58
Joined
Mar 8, 2021
Messages
467
Yes, they appear identical, but if it was me, I would do what I suggested. Walking the code finds what I call the silly/stupid errors.
So many times people here say things are the same when they are not. :(
I'll bow out now, as I am unable to help, and theDBguys suggestion of a sample would be best, as he will find your error.
I hear you but when I walk through the code it doesn't walk (or I don't know how, it stops the code and and resets.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:58
Joined
Oct 29, 2018
Messages
21,358
DBGuy,
When you open the FE, click on Estimates on the switchboard and type in the search boxes at the top, everything works as it should.
Then go to orders and try to type into one of the search boxes at the top, if you type something that is not on the list, the error occurs.
Thanks for the help.
Hi. Thanks! The difference between the two forms is the record source for the Order form is not updatable (it's read only).
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:58
Joined
Oct 29, 2018
Messages
21,358
Is there a way to make this work with a read only record source?
Hi. Out of the office at the moment, but I will download your files again later to take another look.

Sent from phone...
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:58
Joined
Oct 29, 2018
Messages
21,358
Is there a way to make this work with a read only record source?
Hi. I just took another look. Why do you want to keep the query "read only?" It's not read only for the other form (Estimates), and the code works fine there.
 

Users who are viewing this thread

Top Bottom