|
-
Apr 3rd, 2013, 02:26 AM
#1
Thread Starter
Member
Not able to get the textbox focus from one form to another
Friends,
feesentry1:
Code:
Private Sub txtbrno_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyF9 Then
If cmdqry.Enabled = False And cmdedit.Enabled = True And cmdcancel.Enabled = True Then
strqry = "SELECT brno,stdname " _
& "FROM stdentry where (isnull(delstat) or delstat='') order by brno"
Search.Adodc1.RecordSource = strqry
Search.Adodc1.Refresh
Search.Show 1
End If
End If
End Sub
Search Form:
Code:
Private Sub Grid_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
On Error GoTo ErrorHandler:
If Feesentry1.Visible = True And Feesentry1.cmdedit.Enabled = True Then
Feesentry1.txtbrno.Text = Trim(Me.Grid.Columns(0).Value)
End If
Me.Hide
Feesentry1.txtbrno.SetFocus
Exit Sub
ErrorHandler:
MsgBox "No Record found"
Me.Hide
Feesentry1.txtbrno.SetFocus
End If
End Sub
From the above code....i am getting the values from search form to my feesentry1 form...but the control is not coming inside the textbox and the feesentry1 form is also not getting the focus... after getting the value from search form to feesentry1 form i have to click on the textbox of the feesentry1 form. then i have to press enter.
how can i solve this issue?
thanks
-
Apr 3rd, 2013, 03:29 AM
#2
Re: Not able to get the textbox focus from one form to another
 Originally Posted by sathyguy
... but the control is not coming inside the textbox ...
When a Form is shown modally, the owner Form is disabled, including all the controls in it. Eliminate the And Feesentry1.cmdedit.Enabled = True expression in the Grid_KeyPress subroutine of the Search Form.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Apr 3rd, 2013, 05:25 AM
#3
Re: Not able to get the textbox focus from one form to another
Firstly please don't use Data Controls.
Secondly why hide the search form. Unload it instead.
When a form is shown VBModal, and that Form is then Unloaded, control is returned to the original form, and code execution should carry on from the line after the line that showed the VBModal Form.
Thirdly do not be sending instructions to controls on other forms. It is unclean, and also makes debugging a nightmare (It makes trying to read and understand code very difficult)
Additionally it can cause weird results, as it can cause a form to load, before you ask it to.
Have public variables in your forms, and pass data to those variables.
And in some instances, just have a bas file, and place a public variable in there, for passing data.
If you follow my rules, then you won't need to set focus, as the unloading of the frmSearch will return control to frmFeesentry1 and the focus will be in the textbox.
This simple example demonstrates what should happen (if you follow my rules)
Option Explicit
Private Sub txtbrno_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyF9 Then
frmSearch.Show vbModal
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|