Setting field in another form

B

Bill

Can't seem to get the syntax correct for the assignment
statement seen in Sub tbMov3_LostFocus. I need to
set the corresponding text box in the calling form after
focus moves from one control to another. (Only
pertinent code posted below)

Option Compare Database
Option Explicit
Dim strCallingForm As String

Private Sub Form_Open(Cancel As Integer)
Dim Atmp() As String
Dim strStartField As String
'============================================================
' OpenArgs contains the name of the "calling" form and the control name on
that form that
' currently has the focus, separated by a semicolon. There is a one-to-one
correspondance
' between the text box controls on the current and calling forms.
'============================================================
Atmp = Split(Me.OpenArgs, ";")
strStartField = Trim(Atmp(1))
strCallingForm = Trim(Atmp(0))
Me.Controls(strStartField).SetFocus

End Sub
-------------------------------------------------------------------------------------------
Private Sub tbMov3_LostFocus()
If Len(Trim(Me.tbMov3)) > 0 Then
Forms![strCallingForm].Form!Controls("tbmov3") = Me.tbMov3

End Sub
------------------------------------------------------------------------------------------
 
B

Bob Hairgrove

Can't seem to get the syntax correct for the assignment
statement seen in Sub tbMov3_LostFocus. I need to
set the corresponding text box in the calling form after
focus moves from one control to another. (Only
pertinent code posted below)

Option Compare Database
Option Explicit
Dim strCallingForm As String

Private Sub Form_Open(Cancel As Integer)
Dim Atmp() As String
Dim strStartField As String
'============================================================
' OpenArgs contains the name of the "calling" form and the control name on
that form that
' currently has the focus, separated by a semicolon. There is a one-to-one
correspondance
' between the text box controls on the current and calling forms.
'============================================================
Atmp = Split(Me.OpenArgs, ";")
strStartField = Trim(Atmp(1))
strCallingForm = Trim(Atmp(0))
Me.Controls(strStartField).SetFocus

End Sub
-------------------------------------------------------------------------------------------
Private Sub tbMov3_LostFocus()
If Len(Trim(Me.tbMov3)) > 0 Then
Forms![strCallingForm].Form!Controls("tbmov3") = Me.tbMov3

End Sub
------------------------------------------------------------------------------------------

You're almost there! Just change the last line to this:
Forms(strCallingForm).tbmov3 = Me.tbMov3

(and don't forget "End If" if this is really on a separate line.)
 
B

Bill

Great! I tried to find syntax references regarding the
forms collection, but seemed to find everything but.
Was that particular syntax available in A2K?
Bill

Can't seem to get the syntax correct for the assignment
statement seen in Sub tbMov3_LostFocus. I need to
set the corresponding text box in the calling form after
focus moves from one control to another. (Only
pertinent code posted below)

Option Compare Database
Option Explicit
Dim strCallingForm As String

Private Sub Form_Open(Cancel As Integer)
Dim Atmp() As String
Dim strStartField As String
'============================================================
' OpenArgs contains the name of the "calling" form and the control name on
that form that
' currently has the focus, separated by a semicolon. There is a one-to-one
correspondance
' between the text box controls on the current and calling forms.
'============================================================
Atmp = Split(Me.OpenArgs, ";")
strStartField = Trim(Atmp(1))
strCallingForm = Trim(Atmp(0))
Me.Controls(strStartField).SetFocus

End Sub
-------------------------------------------------------------------------------------------
Private Sub tbMov3_LostFocus()
If Len(Trim(Me.tbMov3)) > 0 Then
Forms![strCallingForm].Form!Controls("tbmov3") = Me.tbMov3

End Sub
------------------------------------------------------------------------------------------

You're almost there! Just change the last line to this:
Forms(strCallingForm).tbmov3 = Me.tbMov3

(and don't forget "End If" if this is really on a separate line.)
 
B

Bob Hairgrove

Great! I tried to find syntax references regarding the
forms collection, but seemed to find everything but.
Was that particular syntax available in A2K?
Bill

It was in Access 97 already, or even as early as Access 2 -- but you
needed to always use the bang instead of the dot in Access 2, IIRC.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top