Setting a controls value with code

  • Thread starter Thread starter Cameron Piper
  • Start date Start date
C

Cameron Piper

I have two questions about referring to controls in VBA
code.

1. I have several forms that I am working on that I
would like to add some command buttons to for convenience
sake. Can anyone give me some VBA syntax to set the
value of a control (text box and/or combo box) in a pop
up form based on the value that that control has in the
main form. I have no problem leaving the form in the
background if needed. I would also have no problem using
openargs if necessary, but only if openargs work only
when needed. For instance, I have a form that I use to
imput activities as they relate to a client, sometimes I
open a blank form and choose their clientID from a combo
box, and in the ideal world I would like to be able to
open that same form from the client's record and have the
clientID prefilled for me. The second instance the
openargs would be used, but in the first instance there
wouldn't be another form from which the pop up was opened
therefore no open args. Can you do this, or would it
cause an error when the blank form is opened without a
master form already open?

2. I would also like to get some help on timestamping
and setting a yes/no value when a "complete" button is
clicked. On "frmActivity," I have a "cmdComplete"
(button). I would like to fill in the "DateTimeComplete"
text field using the now function and change
the "Completed" yes/no field to yes. I would like to
complete all of this in the on click event
of "cmdComplete." All of the information will reside in
tblActivity (in case it is needed).

If anyone could show me an example to work off of or
point me to some code syntax it would be greatly
appreciated.

Thanks in advance.

Cameron Piper
CSPiper remove at CBBurnet.com
 
1) Use the Where argument of the DoCmd.OpenForm method to achieve this. For
example:

DoCmd.OpenForm "frmCustomers",,,"lngCustomerID=" & Me.lngCustomerID
Note: this is aircode, not sure about the correct number of commas, check
online help for full syntax

2) In the Click event of your button:

Me.dteCompletedDate = Now()
Me.chkCompleted = True

This assumes that dteCompletedDate and chkCompleted are controls on your
form, with a valid Controlsource set. You'll have to change the fieldnames
to match the ones on your form, of course.
 
Back
Top