Button Click Event

F

fireytech

I have created a launch form which asks the user to enter the
datepayperiod (pay period end date) and their vendorID (employee
number). I have created a button for them to click to open our time
sheet form (frm_timesheet) and automatically carry the pay period date
and the vendorid to the new form. I did this to prevent the user from
editing the pay period date or their vendorid fields on the data entry
form.

I know how to make the form take one field and carry it to the new
form but I don't know how to make it carry both the datepayperiod and
vendorid fields to the data entry form.

Here is the code I have so far:

Private Sub CreateNewTimesheet_Click()
On Error GoTo Err_CreateNewTimesheet_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FRM_Timesheet"
DoCmd.OpenForm stDocName, , , acFormAdd
Forms(stDocName)![VendorID] = Me.[VendorID]
Exit_CreateNewTimesheet_Click:
Exit Sub

Err_CreateNewTimesheet_Click:
MsgBox Err.Description
Resume Exit_CreateNewTimesheet_Click
End Sub

Thanks in advance!
 
K

Ken Snell \(MVP\)

I assume that this step is what you mean by "carrying" the value to the
newly opened form:

Forms(stDocName)![VendorID] = Me.[VendorID]

If this is what you mean, just add a second code line that assigns the
desired pay period date to the appropriate control on the newly opened form.
 
F

fireytech

Yes, this line is the line which "carries" the vendorid to the data
entry form. I know that I need additional code to "carry" the
payperiod date forward as well. That is what I need help with. I
don't know how to do that. Please help further.
 
K

Ken Snell \(MVP\)

Maybe I am missing something here, but this should work:

Forms(stDocName)![NameOfControlForPayPeriodDate] =
Me.[PayPeriodDateFieldOrControl]
 
F

fireytech

Here is what I put in and it still just opens the form and enters the
vendorID only. The payperiod field stays blank:

Private Sub CreateNewTimesheet_Click()
On Error GoTo Err_CreateNewTimesheet_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FRM_Timesheet"
DoCmd.OpenForm stDocName, , , acFormAdd
Forms(stDocName)![VendorID] = Me.[VendorID]
Forms(stDocName)![PayPeriod] = Me.[PayPeriod]
Exit_CreateNewTimesheet_Click:
Exit Sub

Err_CreateNewTimesheet_Click:
MsgBox Err.Description
Resume Exit_CreateNewTimesheet_Click
End Sub
 
K

Ken Snell \(MVP\)

Does the Me.[PayPeriod] control/field actually have a value? Is it a control
or a field? If a field, are you saving the record that is associated with
that field before clicking the button to open the second form?

What datatype is the PayPeriod control/form? What is its Format property?
Same two questions for the PayPeriod control/field on the second form.

Is an error occurring in your code on this step, such that your error
handler is being called and thus the value isn't being set in your second
form?
Forms(stDocName)![PayPeriod] = Me.[PayPeriod]
 
F

fireytech

the "payperiod" is a field in the table that both forms use. there
will be data present in the timesheetlaunch form but not present in
the form we are going to until we move it. I don't think the record
is saving when the button is clicked so maybe that is part of the
problem?

payperiod data is structured as date/time

the last question about the error. it is popping the error when the
form opens. if i just use the form by itself without clicking the
button to get to it is the same.
 
K

Ken Snell \(MVP\)

I am traveling for work, which is delaying my reply to your post. I'll post
as soon as I can.
 
K

Ken Snell \(MVP\)

Am I understanding correctly? You're entering a value for the payperiod on
the form and then clicking the button to carry that value to the second
form? Where on the form is the button located -- in which section of the
form? Is the form on which you're entering the payperiod data a continuous
forms view or single forms view?

What is the name of the form's control that holds the entered payperiod
value?

It would appear to me that the form cannot "see" the data value and thus is
not able to carry it to the other form. Please provide as much detail about
the form and what you do on the form before clicking the button.
 

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