Subform, focus, write & delete

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everybody, I'm having a problem and thought that you guys can help me out

In a form, called Form1, to register the Products I have 3 fields: Name of the product, Unit (you select it from a List) and Category. This form also have a button to launch a subform to create a New Unit for this product (if needed).

When someone creates a New Unit, the Form1 must be refreshed for the new unit to be available in the List. Due to the field Unit is required in the table, you can't refresh the Form1 if that field is empty. So the user is forced to select any value, refresh and then select the value he just created.

I wanna to create a control to make this automatic. I want an event that does the following when you finish the creation of the new unit

1. Set the focus in the Form1
2. Write any value in the Unit field
3. Refresh the Form1
4. Erase the value in the Unit field (so it shows empty
5. Set the focus in the Unit field (so the user can select the new unit)

My problem is that I don't know how to do the steps 2 & 4. If any of you can help me with this one I'll be very thankful

Thanks a lot

Giancarlo
 
Emptiness said:
Hi everybody, I'm having a problem and thought that you guys can help
me out.

In a form, called Form1, to register the Products I have 3 fields:
Name of the product, Unit (you select it from a List) and Category.
This form also have a button to launch a subform to create a New Unit
for this product (if needed).

When someone creates a New Unit, the Form1 must be refreshed for the
new unit to be available in the List. Due to the field Unit is
required in the table, you can't refresh the Form1 if that field is
empty. So the user is forced to select any value, refresh and then
select the value he just created.

I wanna to create a control to make this automatic. I want an event
that does the following when you finish the creation of the new unit:

1. Set the focus in the Form1.
2. Write any value in the Unit field.
3. Refresh the Form1.
4. Erase the value in the Unit field (so it shows empty)
5. Set the focus in the Unit field (so the user can select the new
unit).

My problem is that I don't know how to do the steps 2 & 4. If any of
you can help me with this one I'll be very thankful.

Thanks a lot,

Giancarlo

You're in luck! You do *not* need to refresh the form to get the new
Unit to appear in the combo box. All you need to do is requery the
combo box, which doesn't require saving the form's current record. If
you set the command button that launches your "New Unit" form (which is
not a subform, by the way) so that the New Unit form is opened in dialog
mode, then you can requery the combo box in code immediately following
the OpenForm statement. It might look something like this:

Private Sub cmdAddUnit_Click()

DoCmd.OpenForm "frmUnit", _
DataMode:=acFormAdd, _
WindowMode:=acDialog

Me!Unit.Requery

End Sub
 
Emptiness...reminds me of the days I carried around "The
Pocket Nietszche"... :)

Steps 2 & 4 are, assuming that the combo box Unit displays
English but actually stores the numeric primary key, and
that the control whose Control Source is the field Unit,
but whose name is cboUnit:

Me!cboUnit = 1
Me!cboUnit = Null

If Unit is actually text, change the 1 to any unit that is
actually in your "lookup" table, such as "EA".

HTH
Kevin Sprinkel
-----Original Message-----
Hi everybody, I'm having a problem and thought that you guys can help me out.

In a form, called Form1, to register the Products I have
3 fields: Name of the product, Unit (you select it from a
List) and Category. This form also have a button to launch
a subform to create a New Unit for this product (if
needed).
When someone creates a New Unit, the Form1 must be
refreshed for the new unit to be available in the List.
Due to the field Unit is required in the table, you can't
refresh the Form1 if that field is empty. So the user is
forced to select any value, refresh and then select the
value he just created.
I wanna to create a control to make this automatic. I
want an event that does the following when you finish the
creation of the new unit:
1. Set the focus in the Form1.
2. Write any value in the Unit field.
3. Refresh the Form1.
4. Erase the value in the Unit field (so it shows empty)
5. Set the focus in the Unit field (so the user can select the new unit).

My problem is that I don't know how to do the steps 2 &
4. If any of you can help me with this one I'll be very
thankful.
 
Thanks a lot to both of you... I'll try to fix the problem right now. As should know by now, I'm not an expert in acces, didn't know the commands for programming, so I have to find my way using the commands I already know.

Thanks a lot, using the requery and the command to set values for the fields I'll be able to do a lot of new things ;

PS: you're right Dirk, it's not a subform
 
Back
Top