Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox Setfocus Issues

Status
Not open for further replies.

HGoodloe

Programmer
Sep 4, 2008
53
US
I’m working with the follwing text boxes on a data entry form.

LA Code
Date Prepped
Box Completed (Yes/No field)
Date_Completed
Date_Incomplete

The Date_Completed and Date_Incomplete text boxes are set to invisible until Yes or No has been select in the Box Completed drop down text box. If yes or no has been selected Date_Completed or Date_Incomplete text boxes will appear, at which point when either date has been entered, that completes all the data entry.

After all data has been entered, the add record button is click to add the data to the table. However, upon clicking the add button, a message appears stating the following: Microsoft Access can’t move the focus to control Date_Incomplete. Same thing occurs when selection No except for the message will say can’t move the focus to control Date_Completed.

I am also getting the same message with all the other text boxes. However those problems were resolved when placing the setfocus code right above each text box . For some reason when placing setfocus code above Date_Completed and Date_Incomplete, I get the can’t move the focus to control message when clicking the add record button Does anyone have knowledge of how to resolve this setfocus issue?

The following is the actual code I’m working with.

Private Sub cmdAdd_Click()
On Error GoTo Err_cmdAdd_Click

LA_Code.SetFocus
If Me.LA_Code.Text = "" Then
MsgBox "Please an LA Code", vbInformation
LA_Code.SetFocus
Exit Sub
End If

Date_Prepped.SetFocus
If Me.Date_Prepped.Text = "" Then
MsgBox "Enter Date Prepped", vbInformation
Exit Sub
End If

Completed_Box.SetFocus
If Me.Completed_Box.Text = "" Then
MsgBox "Select Yes or No", vbInformation
Exit Sub
End If

Me.Date_Completed.SetFocus
If Me.Date_Completed.Text = "" Then
MsgBox "Enter a completed date", vbInformation
Exit Sub
End If

Me.Date_Incomplete.SetFocus
If Me.Date_Incomplete.Text = "" Then
MsgBox "Enter a Incompleted date", vbInformation
Exit Sub
End If


DoCmd.GoToRecord , , acNewRec

Exit_cmdAdd_Click:
Exit Sub

Err_cmdAdd_Click:
MsgBox Err.Description
Resume Exit_cmdAdd_Click

End Sub
 
How are ya HGoodloe . . .

You can't set focus to a hidden control! [surprise]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Ok, does the same thing apply to disabling a control(s)?
 
Does the same thing apply to disabled controls?
 

Of course. What good would it do to set focus on a disabled control?

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Try this:
Code:
[blue]   If Trim(Me!LA_Code & "") = "" Then
      MsgBox "Please an LA Code", vbInformation
      Me!LA_Code.SetFocus
   ElseIf Trim(Me!Date_Prepped & "") = "" Then
      MsgBox "Enter Date Prepped", vbInformation
      Me!Date_Prepped.SetFocus
   ElseIf Trim(Me!Completed_Box & "") = "" Then
      MsgBox "Select Yes or No", vbInformation
      Me!Completed_Box.SetFocus
   ElseIf Me!Date_Completed.Enabled Then
      If Not IsDate(Me!Date_Completed) Then
         MsgBox "Enter a valid completed date", vbInformation
         Me!Date_Completed.SetFocus
      End If
   ElseIf Not Me!Date_Incomplete.Enabled Then
      If Not IsDate(Me!Date_Incomplete) Then
         MsgBox "Enter a valid Incompleted date", vbInformation
         Me!Date_Incomplete.SetFocus
      End If
   Else
      DoCmd.RunCommand acCmdSaveRecord
      DoCmd.RunCommand acCmdRecordsGoToNew
   End If[/blue]

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
HGoodloe, try setting the focus to a different field and then making the section you want either invisible or visible.
I've found with a similar project of my own, that you really want to set the Show/Hide section into the OnExit properties of the control that performs that function.

Here's mine...

A Listbox that shows 2 textboxes depending on selection.

Code:
Exit_lstMember_Click:
txtName.SetFocus

Code:
Private Sub lstMember_Exit(Cancel As Integer)
If Left(cboDescription.Value, 10) = "Healthcare" Then
chkRiskP.Visible = True: txtRiskP.Visible = True: Me.Repaint
Else
chkRiskP.Visible = False: txtRiskP.Visible = False: txtRiskP.Value = "0": Me.Repaint
End If
End Sub

HTH,

Jon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top