gotocontrol subform (1 Viewer)

deekras

Registered User.
Local time
Today, 10:10
Joined
Jun 14, 2000
Messages
169
i have a few subforms on the same main form.

the user can fill in as many subforms as necessary. in some of the subforms, if they fill in one field, another few fields must be filled in.

before they move to the next record (on the main form), i want to check that all necessary info is on the subforms.

how do i do that?

on the main form i have a button to go to the next record. before it goes to the next record, it looks for missing data. if data is missing i want a messagebox and then goto that control on the subform.

i got the messagebox part. i just need to know the gotocontrol command.

thanks
 

dcx693

Registered User.
Local time
Today, 05:10
Joined
Apr 30, 2003
Messages
3,265
Write a VBA procedure to check each subform field in turn and display the message box when something required is missing. (It's cool to visit them all, then change the field attributes somehow to mark them as required but missing, say making the background of a text field stand out in bright yellow.)

Use code like this from the main form:
If Me.subForm.Form.Controls("txtField").Value <1 Then
'go to the control
Me.subForm.SetFocus
Me.subForm.Form.Controls("txtField").SetFocus
End If
 

dcx693

Registered User.
Local time
Today, 05:10
Joined
Apr 30, 2003
Messages
3,265
By the way, in that code snippet, you might be wondering why moving the focus to the txtField field involves two steps:

1- Me.subForm.SetFocus

and then,

2- Me.subForm.Form.Controls("txtField").SetFocus

In truth, I've just done it this way because it won't work otherwise. I think that when moving from a form to a subform, you need to make the subform active before you can move the focus to a control on it. However, you can directly access the value of a control, like I did with this line:
Me.subForm.Form.Controls("txtField").Value

If someone out there can provide a better explanation, I'd appreciate it.
 

kingsgambit

Registered User.
Local time
Today, 10:10
Joined
May 27, 2001
Messages
134
I am trying to use your code, but the field on the subform is a combo box. This is what my code looks like

If Me.subformquote.Form.Controls("Type").Value = "" Then
MsgBox "Please enter a Labour type", vbQuestion, "Labour Error"
Me.subformquote.SetFocus
Me.subformquote.Form.Controls("Type").SetFocus

Can you see why it does not work it says it can not find the field type?
 

WayneRyan

AWF VIP
Local time
Today, 10:10
Joined
Nov 19, 2002
Messages
7,122
king,

Try renaming your table's and form's field to something
like LaborType.

Type is a reserved word in Access.

Wayne
 

Users who are viewing this thread

Top Bottom