SetFocus not responding

jketcher

Registered User.
Local time
Today, 03:48
Joined
Apr 15, 2009
Messages
77
Help again! I think I have a syntax error with a SetFocus command. I am trying to navigate back to a specific place on a different form and it is ignoring my code.

Forms!Switchboard!AddFindings.SetFocus

After an error message displays, I am attempting to navigate from a Form named frm_edit_findings to a form named 'Switchboard' which has a tab named AddFindings. I would like focus to go to the field 'Category', but can't even get it to the add findings tab. Is there another method I should be using to do this?

Thanks!
 
You don't need to include the tab in the reference, just the control.
 
I changed the syntax to Forms!Switchboard!Category.SetFocus and it still didn't work. Category is the control I want to receive the focus.
 
What event is the code in? You probably have to set focus to the form first:

Forms!Switchboard.SetFocus
 
It is in an OnClick event. User clicks on a control, the error condition is met and message displays. Then want navigation away from that form/control to another form/control.
 
Did you try what I posted? I just tested, and you do need both lines.
 
I have a new related issue. I am now navigating back to whichever tab I name but need to requery or do something to refresh the data from the table so that the deleted record does not display in the list any more.

1. Delete record using sub form - frm_edit_findings
2. Return control back to parent form 'Switchboard' tab [Edit Findings]
3. The deleted record still shows up in the list.

Where do I do the requery -- in the sub form or the parent form when enter the tab display?

Is there another method I should be using?

How do I trigger this requery? There is no event on the tab control that will activate a requery because I am not moving the cursor, clicking etc.
The record is gone but the text in the control is still there.

If this one gets solved, I think I can turn it over to the users for a final test.
 
You requery whatever form or subform is displaying the record (sounds like Switchboard). You might requery it in the code that moves focus back to that form, or in the code that deletes the record on the other form, or perhaps the activate event of that form.
 
This is regarding editing of the same database. I have now put all editing in the Close event. I am anticipating the users will use several methods to delete data and due to the design of this database, I have to check for nulls, spaces etc. What is the best way to cover everything? If the Delete key is used to delete data after it is highlighted (this is lengthy text in the form of paragraphs) what is in the text box after the delete? Checking for nulls does not work. Spaces or "" or " " isn't addressing it either. Some users could also use the backspace key.

Thanks, Jketcher
 
I usually test for Null and ZLS ("") with

If Len(Me.ControlName & vbNullString) = 0 Then

You can try adding Trim() to that to catch entries with just spaces.
 
Does VBA have trouble with 'Or Not' conditions (like Cobol)? Here is my code:

‘Check if Finding2 is empty and Info 2 is not empty
If (IsNull(Me.Finding2) Or Me.Finding2 = ("")) And (Not IsNull(Me.Info2) Or Me.Info2 <> ("")) Then
Finding2.BorderColor = vbRed
Finding2.SetFocus
MsgBox "Message 1”
Entry_Error = "Yes"
Cancel = True
Else
‘Check if Finding 2 is not empty and Info 2 is Empty
If (Not IsNull(Me.Finding2) Or Me.Finding2 <> ("")) And (IsNull(Me.Info2) Or Me.Info2 = ("")) Then
Info2.BorderColor = vbRed
Info2.SetFocus
MsgBox "Message 2”
Entry_Error = "Yes"
Cancel = True
Else
‘Check if both Finding2 and Info2 are empty and if there needs to be text entered – the text box is
‘between two Findings boxes that have text in them (not empty)
If Not IsNull(Me.Finding1) And Not IsNull(Me.Finding3) _
And (IsNull(Me.Finding2) Or Me.Finding2 = ("")) Then
MsgBox "Message 3"
Info2.BorderColor = vbRed
Finding2.BorderColor = vbRed
Finding2.SetFocus
Cancel = True
Entry_Error = "Yes"
End If
End If
End If

The two text boxes have different information but are dependent upon each other. If one is entered the other has to be entered and vice versa. When testing, I am deleting text in each of the two boxes expecting to get Message 3, but it is landing in the wrong error condition and am getting Message 1. I did a little test at the beginning of the script and found that when I enter the delete or backspace keys on the text field, VBA thinks it is (""). When I first enter the code with an empty text field, it thinks it is nulls. How can I get this to work? I hope it didn't give you a headache.

Thanks, jketcher
 
It can do that type of test, but I suspect the logic is wrong. If the second textbox is Null I think it will pass the OR part of the second test (Me.Info2 <> ("")), so that condition will be true and you'll get the first message box. I'd switch to my test, as it's easier to understand visually. Test for = 0 for Null/ZLS, > 0 for populated.
 
Can you spell it out? ZLS stands for? Sorry, don't know the lingo. I tried using the 'If Len(Me.Finding2 & vbNullString) = 0' and it had the same effect so I took it out of the one set of code I am using for testing. It is still in the rest of the code for the other nine box combinations. So I need a little more help... Thanks.
 
ZLS is the zero length string:


Try

If Len(Me.Finding2 & vbNullString) = 0 And Len(Me.Info2 & vbNullString) > 0 Then

The repeating fields hint at a normalization problem.
 

Users who are viewing this thread

Back
Top Bottom