Access can't move focus to control

pbuethe

Returning User
Local time
Today, 16:43
Joined
Apr 9, 2002
Messages
210
I have a tab control on my form. In the change event of the tab control I am trying to tell it to move to the first field on each page of the tab control whenever the page no. changes:

Code:
Private Sub TabScreenAssess_Change()
    'when a new page gets the focus, set the focus to the first control on that page
    Dim PageNo As Integer
    
    PageNo = Me!TabScreenAssess.Value
    Select Case PageNo
        Case "0": gynFemale.SetFocus
        Case "1": tbPriorHx.SetFocus
        Case "2": suSubUseAssess.SetFocus
        Case "3": mhaCognitiveFunct.SetFocus
    End Select

End Sub
This works when I am tabbing normally through the controls. But when I click back to the first tab, it says "Access can't move the focus to the control gynFemale" (gynFemale is the first control on the first tab.) It works for the other tabs. That is when I click on another tab, the focus goes to the first field on that tab. When I enter a value in the gynFemale field (it is a combobox, with options Yes or No), sometimes it appears to save the value, then I discover that it has been saved as record #0.

Any help with these problems is appreciated.
 
Forgive my ignorance, but can't you achieve this by simply setting the "Tab Order" correctly for each page?
 
bradcccs,

Thanks for your response. I checked the tab order and it was correct. I have now removed this code since it was complicating the problem. The real problem is that Access is creating a record with a primary key of 0 instead of saving under the current record. This form is based on a query with 3 tables, tblHeader, tblGYN, and tblPartB. Here is the SQL of the query:


SELECT tblHeader.CaseNbr, tblHeader.FacilityName, tblHeader.patLName, tblHeader.patFName, tblGYN.gynFemale, tblGYN.gynExam, tblGYN.gynPAPSmear, tblGYN.gynPAPAbnormalRes, tblGYN.gyn2ndPapRef, tblGYN.gynRefGYN, tblGYN.gynGonTest, tblGYN.gynGonPos, tblGYN.gynGonTreated, tblGYN.gynChlamCulture, tblGYN.gynChlamPos, tblGYN.gynChlamTreated, tblPartB.tbPriorHx, tblPartB.tbPPDPlacedRead, tblPartB.tbPPDPositive, tblPartB.tbPPDPlacedNotRead, tblPartB.SyphilisScreening, tblPartB.suSubUseAssess, tblPartB.suSubUseIdent, tblPartB.suSafeInj, tblPartB.suTobUse, tblPartB.suSmoker, tblPartB.mhaCognitiveFunct, tblPartB.mhaDepressionScrn, tblPartB.mhaAnxietyScrn, tblPartB.mhaPsychiatricHx, tblPartB.mhaPsychosocialAssess, tblPartB.mhaSleepHabitsAssess, tblPartB.mhaAppetiteAssess
FROM (tblPartB RIGHT JOIN tblHeader ON tblPartB.CaseNbr = tblHeader.CaseNbr) LEFT JOIN tblGYN ON tblHeader.CaseNbr = tblGYN.CaseNbr;


What is happening is that it is saving to tblGYN under record #0. (It saves to tblPartB under the correct record number.) The first page of the tab control contains the fields from tblGYN. The other pages contain the fields from tblPartB. I hope I have explained it enough.

***
I discovered that when I moved my record search fields and code off the header form to their own form, I did not delete the DIM statement in the header code that created a recordset. After I removed that, it seemed that the tblGYN fields were saving, but not two tblPartA fields that are in a different form. However, after trying "inconsistent updates" and changing field lengths, it seems that all the fields on this form (tblGYN and tblPartB) are saving to record #0 again.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom