Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009

    Unanswered: Error 2110 Can't Setfocus


    I have a subform that when you press the 'Close' button the focus should change to a control on the main form and the subform becomes invisible. But when I click it this error appears.

    First things first, the new focus is enabled and visible.

    I think the problem is that I am running a BeforeUpdate method on a textbox.

    Why BeforeUpdate:

    The subform shows the details of a record that is selected from the main form. If you were to change a field of the record then the main table is not updated with the new value of the field. (The subform allows edits)

    So I used an update query, I put the query on Change, but this didn't work as it took the value of the field before the new value had been entered. I then used BeforeUpdate which worked perfectly.

    But when I came to use the Close button, this error occured saying that it won't let me move the focus.

    I'm not sure what I am doing wrong...

    Edit: I have tried it as AfterUpdate and get the same error

    Last edited by pb190; 12-09-09 at 07:53. Reason: development?

  2. #2
    Join Date
    Jun 2005
    Richmond, Virginia USA
    Provided Answers: 19
    When asking for help in debugging code it is always a good idea to actually post the code you're using. A little clearer explanation of what you're doing would also help. Are you saying that the "subform" has the same RecordSource as the main form, and you're simply using it to edit records from the main form?
    Hope this helps!

    The problem with making anything that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Nov 2009

    Here is the Close Button coding:

    Private Sub Close_Click()
    Forms![Summary]!Booking.Visible = False
    End Sub

    Summary is the name of the Main form and Booking is the name of the subform.

    As you can see this is not the problem, I think it could be After/Before Update, which is below:

    Dim SQL As String
    Dim strses As String

    DoCmd.SetWarnings (False)
    strses = "'" & SessionName.Value & "'"
    SQL = "UPDATE Bookings SET Bookings.[SessionName] =" & strses & " " & _
    "WHERE (((Bookings.[Week No]) =[Forms]![Summary]![WeekNo]) AND ((Bookings.SessionName)=[Forms]![Summary]![SessionNamebox]));"
    DoCmd****nSQL SQL
    Forms![Summary]!SessionNamebox.Value = SessionName.Value
    DoCmd.SetWarnings (True)
    Call Bookings

    SessionName is a textbox that is linked to the Bookings table.
    The SQL is an update query to amend the record with the new session name written in the SessionName textbox.
    SessionNamebox is a textbox that is used to query the subform Booking. Therefore this would need to change to fit the new Sessionname for the record.
    Bookings is a Public Sub that assigns each of the records that fits certain criteria to a label.

    So on the main form, when Bookings Public Sub is run labels appear each with a defined SessionName (this makes up the caption for each label). When you select one of the labels that you wish to modify the SessionName is copied into the SessionNameBox. The Booking subform appears and based on the string in SessionNameBox the appropiate details are displayed according to which label you selected.

    I have made everyother piece of information modifiable (I know that isn't a real word, just can't thinkof an appropiate real one), so that if you were to change the starting time then the label would change automatically. But the problem is that Start time for instance is a combobox so you can just use the OnChange event, but the SessionName is a textbox and so it is different as explained in my first post.

    The same record source thing is a kinda yes answer. The Bookings Public Sub queries the Bookings Table using criteria, like room, and pastes them into a temptable called Summary. From the Summary table the labels are made and displayed. The main Form doesn't have a record source. The Booking Subform uses the selection of whichever label you selected, to query the Bookings Table to gather the details of the record.

    Hope this makes sense

    Last edited by pb190; 12-09-09 at 10:04.

  4. #4
    Join Date
    Nov 2009
    It seems that this problem is not just linked to the SessionName, I have changed the event to a button and the error still occurs and the error is now occuring with any other modifications that are made to the record. So it is not the update events. So it could be the Bookings Public Sub which is posted below:

    Public Sub Bookings()
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim cap As String
    Dim capmod As String
    Dim x As Integer
    Dim y As Integer
    Dim Left As String
    Dim Start As Date
    Dim StartTime As Integer
    Dim width As Date

    DoCmd.SetWarnings (False)
    CurrentDb.Execute "DELETE from SummaryTable"
    SQL = "INSERT INTO SummaryTable (SessionName, [Week No], Weekday, DateofBooking, [Start Time], [End Time], [Module Code], Room, [Booked By], Description ) " & _
    "SELECT Bookings.SessionName, Bookings.[Week No], Bookings.Weekday, Bookings.DateofBooking, Bookings.[Start Time], Bookings.[End Time], Bookings.[Module Code], Bookings.Room, Bookings.[Booked By], Bookings.Description " & _
    "FROM Rooms INNER JOIN (Modules INNER JOIN Bookings ON Modules.[Module Code] = Bookings.[Module Code]) ON Rooms.Room = Bookings.Room " & _
    "WHERE (((Bookings.[Week No])=[Forms]![Summary]![WeekNo]) AND ((Bookings.Weekday)=[Forms]![Summary]![Weekday]) AND ((Bookings.Room)=[Forms]![Summary]![Room]));"

    DoCmd****nSQL SQL

    For y = 1 To 10
    Forms("Summary").Controls("Session" & y).Visible = False
    Forms("Summary").Controls("Session" & y).Left = "0"
    Next y
    Set db = CurrentDb
    Set rs = db.OpenRecordset("summaryTable", dbOpenDynaset)
    x = 1
    Do While Not rs.EOF
    If rs.RecordCount = 0 Then
    Exit Do
    End If
    cap = rs![SessionName]
    capmod = rs![Module Code]
    Start = (((Hour(rs![Start Time]) - 8) * 60) + Minute(rs![Start Time])) / 30
    StartTime = 1000 + (435 * Start)
    width = (((((Hour(rs![End Time]) - 8) * 60) + Minute(rs![End Time])) / 30) - Start) * 435
    Forms("Summary").Controls("Session" & x).Visible = True
    Forms("Summary").Controls("Session" & x).Caption = cap & vbCrLf & capmod
    Forms("Summary").Controls("Session" & x).Left = StartTime
    Forms("Summary").Controls("Session" & x).width = width
    x = x + 1
    DoCmd.SetWarnings (True)
    End Sub

    The coding is explained in "Assigning a label to Each Record" in this forum.

    Thanks for anyone that is working on this,


  5. #5
    Join Date
    Nov 2009

    Its all sorted. I removed the Call Bookings line from all of the controls on the subform and used the line in Form_AfterUpdate() so that they press the Update button and everything now works.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts