Open form from another form Via Code

D

Dave Elliott

I have a form named Customers where I want to be able to open another form
named TimeCards with the data linked, that is create a new record, i.e.
TimeCard with the customer data inputted for me.
The below code is not working. The TimeCard form opens to the first record,
no filters.
Also sometimes the TimeCards form is open the same time as the customers
form.
I get a error message saying the object o isnt open.
NameA is the field that will contain the customer on TimeCards form.It is a
lookup field and will fill in the rest after tabbing out of field. Any
Suggestions? Thanks...



On Error GoTo Err_Command17_Click
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "TimeCards"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms![TimeCards]![NameA] = Forms![Customers]![Customers]
DoCmd.GoToRecord , NewRecord
Forms![TimeCards]![Employee] = Forms![Customers]![Employee]
DoCmd.Close acForm, Me.Name

--


---------------------------------------------------------------------
This email and any files transmitted with it from Dave Elliott are
confidential and intended solely for the
use of the individual or entity to whom they are addressed.
If you have received this email in error please notify the
sender.
All Mail is pre-scanned with Norton Antivirus 2004 for your protection.

http://[email protected]
 
G

Gary Miller

Dave,

One problem that I see is that you are assigning NameA
before you go to the new record. Also, you may need a
DoEvents line to wait for the form to initialize. I am also
thinking that the GoToRecord New is going to happen on your
Customer form the way you have it. I will say we want a new
record when I use the OpenForm. Also, although it doesn't
hurt, you don't need the stLinkCriteria as you don't have
any. Try...

On Error GoTo Err_Command17_Click
Dim stDocName As String

stDocName = "TimeCards"
DoCmd.OpenForm stDocName, , , , acFormAdd
DoEvents
Forms![TimeCards]![NameA] =
Forms![Customers]![Customers]
Forms![TimeCards]![Employee] =
Forms![Customers]![Employee]
DoCmd.Close acForm, Me.Name

--

Gary Miller
Gary Miller Computer Services
Sisters, OR
________________________
message
news:[email protected]...
 

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