2 forms connected via relationships/need code to add to CLOSE FORMbutton and....

L

(Lisa Hopkins),

Access 03
I have two forms, MAIN FORM and DUI FORM. They are connected via
relationships 1 to many
On the MAIN FORM I have a code connected to a field check box 1DUI

Private Sub Ctl1DUI_AfterUpdate()
If [1DUI] = True Then
Dim stDocName As String
Dim stCriteria As String
stDocName = "DUI FORM"
stLinkCriteria = "CASENUMBER=" & "'" & Me!CASENUMBER & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , Me.CASENUMBER
End If
End Sub

This opens DUI FORM with the same record casenumber already incerted
on field

On the DUI FORM I have a cndButton to close this form
What I want to happen is when the DUI FORM closes, I want the setfocus
on the next field
on the MAIN FORM which is called PED
This is what I did

Private Sub close_form_in_DUI_FORM_Click()
On Error GoTo Err_close_form_in_DUI_FORM_Click

DoCmd.Close
Form![MAIN FORM].PED.SetFocus

Exit_close_form_in_DUI_FORM_Click:
Exit Sub
Err_close_form_in_DUI_FORM_Click:
MsgBox Err.Description
Resume Exit_close_form_in_DUI_FORM_Click

End Sub

I get this ERROR window:
The expression you entered refers to an object that is closed or
dosen't exist. OK

When I return to the code PED is highlighted and i don't understand
because there is a PED in the table and PED on the MAIN FORM

You need to know that i do not do this stuff for a living, I am
basicly fumbling around
and learning as I go
Patty
 
T

tina

try selecting the form first, before setting focus on the control, as

DoCmd.Close
DoCmd.SelectObject acForm, "MAIN FORM"
Form![MAIN FORM].PED.SetFocus

note that you may have enclose the form name in brackets [], INSIDE the
double quotes, for the code to work. i never allow spaces in my object names
in Access, so i'm not sure of the proper syntax here. (for more information
on naming objects in Access, see
http://home.att.net/~california.db/tips.html#aTip5.

hth
 
M

Marshall Barton

(Lisa Hopkins) said:
Access 03
I have two forms, MAIN FORM and DUI FORM. They are connected via
relationships 1 to many
On the MAIN FORM I have a code connected to a field check box 1DUI

Private Sub Ctl1DUI_AfterUpdate()
If [1DUI] = True Then
Dim stDocName As String
Dim stCriteria As String
stDocName = "DUI FORM"
stLinkCriteria = "CASENUMBER=" & "'" & Me!CASENUMBER & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , Me.CASENUMBER
End If
End Sub

This opens DUI FORM with the same record casenumber already incerted
on field

On the DUI FORM I have a cndButton to close this form
What I want to happen is when the DUI FORM closes, I want the setfocus
on the next field
on the MAIN FORM which is called PED
This is what I did

Private Sub close_form_in_DUI_FORM_Click()
On Error GoTo Err_close_form_in_DUI_FORM_Click

DoCmd.Close
Form![MAIN FORM].PED.SetFocus
I get this ERROR window:
The expression you entered refers to an object that is closed or
dosen't exist. OK


Assuming everything else is ok, that should be:

Forms![MAIN FORM].PED.SetFocus
 
L

(Lisa Hopkins),

(Lisa Hopkins) said:
Access 03
I have two forms, MAIN FORM and DUI FORM. They are connected via
relationships 1 to many
On the MAIN FORM I have a code connected to a field check box 1DUI
Private Sub Ctl1DUI_AfterUpdate()
If [1DUI] = True Then
Dim stDocName As String
Dim stCriteria As String
stDocName = "DUI FORM"
stLinkCriteria = "CASENUMBER=" & "'" & Me!CASENUMBER & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , Me.CASENUMBER
End If
End Sub
This opens DUI FORM with the same record casenumber already incerted
on field
On the DUI FORM I have a cndButton to close this form
What I want to happen is when the DUI FORM closes, I want the setfocus
on the next field
on the MAIN FORM which is called PED
This is what I did
Private Sub close_form_in_DUI_FORM_Click()
On Error GoTo Err_close_form_in_DUI_FORM_Click
DoCmd.Close
Form![MAIN FORM].PED.SetFocus
I get this ERROR window:
The expression you entered refers to an object that is closed or
dosen't exist. OK

Assuming everything else is ok, that should be:

� � � � Forms![MAIN FORM].PED.SetFocus

--
Marsh
MVP [MS Access]- Hide quoted text -

- Show quoted text -

Marsh >>> you were right, added Lisa's code and tried it, nothing,
then went back and just added "s" to Form ! and
WALA !!! it worked, thank you
 
L

(Lisa Hopkins),

(Lisa Hopkins) said:
Access 03
I have two forms, MAIN FORM and DUI FORM. They are connected via
relationships 1 to many
On the MAIN FORM I have a code connected to a field check box 1DUI
Private Sub Ctl1DUI_AfterUpdate()
If [1DUI] = True Then
Dim stDocName As String
Dim stCriteria As String
stDocName = "DUI FORM"
stLinkCriteria = "CASENUMBER=" & "'" & Me!CASENUMBER & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , Me.CASENUMBER
End If
End Sub
This opens DUI FORM with the same record casenumber already incerted
on field
On the DUI FORM I have a cndButton to close this form
What I want to happen is when the DUI FORM closes, I want the setfocus
on the next field
on the MAIN FORM which is called PED
This is what I did
Private Sub close_form_in_DUI_FORM_Click()
On Error GoTo Err_close_form_in_DUI_FORM_Click
DoCmd.Close
Form![MAIN FORM].PED.SetFocus
I get this ERROR window:
The expression you entered refers to an object that is closed or
dosen't exist. OK
Assuming everything else is ok, that should be:
Forms![MAIN FORM].PED.SetFocus
- Show quoted text -

Marsh >>> you were right, added Lisa's code and tried it, nothing,
then went back and just added "s" to Form ! and
WALA !!! it worked, thank you- Hide quoted text -

- Show quoted text -

Don't leave me yet!!! Ok referring to my 1st post, this is all set for
field command 1DUI in MAIN FORM to open another form (DUI FORM)
Now I have also on the MAIN FORM a field called 2DUI which requires
all of the same data imput that is already set up on the DUI FORM
So I figured, simple, I'll just repete the codes I have for
1DUI.....NOT !!! NOT working I mean
What happens is when I check the box on 2DUI to open the DUI FORM, it
now opens with the data from the previous record only with
the new CASENUMBER at the top
think I need to add something to this AfterUpdate code so that when
its a different CASENUMBER (not already entered in the DUI FORM)
the NEW CASENUMBER will be there with blank fields ready for data
imput.
 
M

Marshall Barton

(Lisa Hopkins) said:
(Lisa Hopkins), wrote:
Access 03
I have two forms, MAIN FORM and DUI FORM. They are connected via
relationships 1 to many
On the MAIN FORM I have a code connected to a field check box 1DUI
Private Sub Ctl1DUI_AfterUpdate()
If [1DUI] = True Then
Dim stDocName As String
Dim stCriteria As String
stDocName = "DUI FORM"
stLinkCriteria = "CASENUMBER=" & "'" & Me!CASENUMBER & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , Me.CASENUMBER
End If
End Sub
This opens DUI FORM with the same record casenumber already incerted
on field
On the DUI FORM I have a cndButton to close this form
What I want to happen is when the DUI FORM closes, I want the setfocus
on the next field
on the MAIN FORM which is called PED
This is what I did
Private Sub close_form_in_DUI_FORM_Click()
On Error GoTo Err_close_form_in_DUI_FORM_Click
DoCmd.Close
Form![MAIN FORM].PED.SetFocus
I get this ERROR window:
The expression you entered refers to an object that is closed or
dosen't exist. OK
Assuming everything else is ok, that should be:
Forms![MAIN FORM].PED.SetFocus


Marsh >>> you were right, added Lisa's code and tried it, nothing,
then went back and just added "s" to Form ! and
WALA !!! it worked, thank you- Hide quoted text -

Don't leave me yet!!! Ok referring to my 1st post, this is all set for
field command 1DUI in MAIN FORM to open another form (DUI FORM)
Now I have also on the MAIN FORM a field called 2DUI which requires
all of the same data imput that is already set up on the DUI FORM
So I figured, simple, I'll just repete the codes I have for
1DUI.....NOT !!! NOT working I mean
What happens is when I check the box on 2DUI to open the DUI FORM, it
now opens with the data from the previous record only with
the new CASENUMBER at the top
think I need to add something to this AfterUpdate code so that when
its a different CASENUMBER (not already entered in the DUI FORM)
the NEW CASENUMBER will be there with blank fields ready for data
imput.


How do you set the case number for 1DUI in the DUI form?

Where and what is the code for opening the DUI form for
2DUI?
 

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