Open Sub Form

M

Michelle

I have an Employee Form and form it I have a command button to open the
subform time card. It does open it but what it does not do is add the
employee # to the Time Card Table.
Here is the code I use to open the sub form.
Private Sub OpenTimeCard_Click()
On Error GoTo Err_OpenTimeCard_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTimeCard"

stLinkCriteria = "[EmployeeID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_OpenTimeCard_Click:
Exit Sub

Err_OpenTimeCard_Click:
MsgBox Err.Description
Resume Exit_OpenTimeCard_Click

End Sub

Thanks
Michelle
 
M

Maurice

You are just opening your form based on a criteria that isn't there when the
employee doesn't exists. I assume you want to add it if the employee doesn't
exists right?

try adding the following line after the docmd.openform statement:

forms!frmtimecard!employeeID=me.id

hth
 
M

Michelle

This worked however it only puts the Employee # in for the first line if you
enter more than one line then the rest do not get the Employee #.
Here is my code now.

Private Sub OpenTimeCard_Click()
On Error GoTo Err_OpenTimeCard_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTimeCard"

stLinkCriteria = "[EmployeeID]=" & Me![ID]
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria
Forms!frmtimecard!employeeID = Me.ID
DoCmd.MoveSize 3 * 1440, 2 * 1440, 5.4 * 1440, 7 * 1440

Exit_OpenTimeCard_Click:
Exit Sub

Err_OpenTimeCard_Click:
MsgBox Err.Description
Resume Exit_OpenTimeCard_Click

End Sub


Maurice said:
You are just opening your form based on a criteria that isn't there when the
employee doesn't exists. I assume you want to add it if the employee doesn't
exists right?

try adding the following line after the docmd.openform statement:

forms!frmtimecard!employeeID=me.id

hth
--
Maurice Ausum


Michelle said:
I have an Employee Form and form it I have a command button to open the
subform time card. It does open it but what it does not do is add the
employee # to the Time Card Table.
Here is the code I use to open the sub form.
Private Sub OpenTimeCard_Click()
On Error GoTo Err_OpenTimeCard_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTimeCard"

stLinkCriteria = "[EmployeeID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_OpenTimeCard_Click:
Exit Sub

Err_OpenTimeCard_Click:
MsgBox Err.Description
Resume Exit_OpenTimeCard_Click

End Sub

Thanks
Michelle
 
M

Maurice

Michelle,

I get it you are using a continuous form... In that case try the following
line

Forms!frmtimecard!employeeID.defaultvalue = Me.ID
this will set the defaultvalue for employeeID to me.id

if that doesn't do the trick try adding an unbound textbox (hidden) where
you place the me.id the same way as Forms!frmtimecard!textbox = Me.ID. Now
when you enter a new record you can set the employeeID to the value of the
textbox.

You can do this in an after update from another textbox of your form like:

me.employeeid=me.textbox (where textbox is the name of your hidden control).
hth

--
Maurice Ausum


Michelle said:
This worked however it only puts the Employee # in for the first line if you
enter more than one line then the rest do not get the Employee #.
Here is my code now.

Private Sub OpenTimeCard_Click()
On Error GoTo Err_OpenTimeCard_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTimeCard"

stLinkCriteria = "[EmployeeID]=" & Me![ID]
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria
Forms!frmtimecard!employeeID = Me.ID
DoCmd.MoveSize 3 * 1440, 2 * 1440, 5.4 * 1440, 7 * 1440

Exit_OpenTimeCard_Click:
Exit Sub

Err_OpenTimeCard_Click:
MsgBox Err.Description
Resume Exit_OpenTimeCard_Click

End Sub


Maurice said:
You are just opening your form based on a criteria that isn't there when the
employee doesn't exists. I assume you want to add it if the employee doesn't
exists right?

try adding the following line after the docmd.openform statement:

forms!frmtimecard!employeeID=me.id

hth
--
Maurice Ausum


Michelle said:
I have an Employee Form and form it I have a command button to open the
subform time card. It does open it but what it does not do is add the
employee # to the Time Card Table.
Here is the code I use to open the sub form.
Private Sub OpenTimeCard_Click()
On Error GoTo Err_OpenTimeCard_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTimeCard"

stLinkCriteria = "[EmployeeID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_OpenTimeCard_Click:
Exit Sub

Err_OpenTimeCard_Click:
MsgBox Err.Description
Resume Exit_OpenTimeCard_Click

End Sub

Thanks
Michelle
 
M

Michelle

That worked perfectly!
Thanks
Michelle

Maurice said:
Michelle,

I get it you are using a continuous form... In that case try the following
line

Forms!frmtimecard!employeeID.defaultvalue = Me.ID
this will set the defaultvalue for employeeID to me.id

if that doesn't do the trick try adding an unbound textbox (hidden) where
you place the me.id the same way as Forms!frmtimecard!textbox = Me.ID. Now
when you enter a new record you can set the employeeID to the value of the
textbox.

You can do this in an after update from another textbox of your form like:

me.employeeid=me.textbox (where textbox is the name of your hidden control).
hth

--
Maurice Ausum


Michelle said:
This worked however it only puts the Employee # in for the first line if you
enter more than one line then the rest do not get the Employee #.
Here is my code now.

Private Sub OpenTimeCard_Click()
On Error GoTo Err_OpenTimeCard_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTimeCard"

stLinkCriteria = "[EmployeeID]=" & Me![ID]
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria
Forms!frmtimecard!employeeID = Me.ID
DoCmd.MoveSize 3 * 1440, 2 * 1440, 5.4 * 1440, 7 * 1440

Exit_OpenTimeCard_Click:
Exit Sub

Err_OpenTimeCard_Click:
MsgBox Err.Description
Resume Exit_OpenTimeCard_Click

End Sub


Maurice said:
You are just opening your form based on a criteria that isn't there when the
employee doesn't exists. I assume you want to add it if the employee doesn't
exists right?

try adding the following line after the docmd.openform statement:

forms!frmtimecard!employeeID=me.id

hth
--
Maurice Ausum


:

I have an Employee Form and form it I have a command button to open the
subform time card. It does open it but what it does not do is add the
employee # to the Time Card Table.
Here is the code I use to open the sub form.
Private Sub OpenTimeCard_Click()
On Error GoTo Err_OpenTimeCard_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTimeCard"

stLinkCriteria = "[EmployeeID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_OpenTimeCard_Click:
Exit Sub

Err_OpenTimeCard_Click:
MsgBox Err.Description
Resume Exit_OpenTimeCard_Click

End Sub

Thanks
Michelle
 
M

Marshall Barton

Michelle said:
This worked however it only puts the Employee # in for the first line if you
enter more than one line then the rest do not get the Employee #.
Here is my code now.

stLinkCriteria = "[EmployeeID]=" & Me![ID]
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria
Forms!frmtimecard!employeeID = Me.ID


Don't set the Value property. That would dirty an existing
record. Instead, set the DefaultValue property, which is
only used on new records.
 
M

Michelle

You helped me with this I have a quesion....how would you do this if both
fields were text instead of numbers.
I have anothe db and I can not seem to get this to work on them.
Here is what I have....
I have a main from called Equipment it has 2 subforms one for the IP Data and
one for Budget Data.
When I cleck the command button it opens the sub form however it does not
seem to copy the IDTag to the subfrom IDTag area so that everything is linked
together right.
My Tables are:
tblEquipment
IDTag - Txt & PK
EquipmentType
Location
LocationDesc
Mfg
Model
SerialNum
PONum
Contract
WarType
WarExpDate
Surplus
SurplusDate
InventoryDate
Notes

tblBudgeting
ID - Auto # & PK
EquipmentID - Txt
BdgYear
Expenditure
Purpose

tblIPData
ID -Auto # & PK
EquipmentID - txt
MAC
IP
SN
GW
PDNS
SDNS
Wireless

Relationships are:
tblEquipment to tblBudgeting on IDTag = IDTag One-To-Many all from
tblEquipment and only those from tblBudgeting where fields are equal.
tblEquipment to tblIPData on IDTag = EIDTag One-To-Many all from
tblEquipment and only those from tblIPData where fields are equal.

Here is my code for the command buttons:
IPData
Private Sub IPData_Click()
On Error GoTo Err_IPData_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmIPData"

stLinkCriteria = "[EquipmentID]=""" & Me![IDTag] & """"
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria
Forms!frmIPData!equipmentid.DefaultValue = Me.IDTag
DoCmd.MoveSize 3 * 1440, 2 * 1440, 9.5 * 1440, 5 * 1440

Exit_IPData_Click:
Exit Sub

Err_IPData_Click:
MsgBox Err.Description
Resume Exit_IPData_Click
End Sub

Budget
Private Sub Budget_Click()
On Error GoTo Err_Budget_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmBudget"

stLinkCriteria = "[EquipmentID]=" & Me![IDTag]
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria
Forms!frmbudget!equipmentid.DefaultValue = Me.IDTag
DoCmd.MoveSize 3 * 1440, 2 * 1440, 5.4 * 1440, 7 * 1440

Exit_Budget_Click:
Exit Sub

Err_Budget_Click:
MsgBox Err.Description
Resume Exit_Budget_Click


End Sub


Maurice said:
Michelle,

I get it you are using a continuous form... In that case try the following
line

Forms!frmtimecard!employeeID.defaultvalue = Me.ID
this will set the defaultvalue for employeeID to me.id

if that doesn't do the trick try adding an unbound textbox (hidden) where
you place the me.id the same way as Forms!frmtimecard!textbox = Me.ID. Now
when you enter a new record you can set the employeeID to the value of the
textbox.

You can do this in an after update from another textbox of your form like:

me.employeeid=me.textbox (where textbox is the name of your hidden control).
hth

--
Maurice Ausum


Michelle said:
This worked however it only puts the Employee # in for the first line if you
enter more than one line then the rest do not get the Employee #.
Here is my code now.

Private Sub OpenTimeCard_Click()
On Error GoTo Err_OpenTimeCard_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTimeCard"

stLinkCriteria = "[EmployeeID]=" & Me![ID]
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria
Forms!frmtimecard!employeeID = Me.ID
DoCmd.MoveSize 3 * 1440, 2 * 1440, 5.4 * 1440, 7 * 1440

Exit_OpenTimeCard_Click:
Exit Sub

Err_OpenTimeCard_Click:
MsgBox Err.Description
Resume Exit_OpenTimeCard_Click

End Sub


Maurice said:
You are just opening your form based on a criteria that isn't there when the
employee doesn't exists. I assume you want to add it if the employee doesn't
exists right?

try adding the following line after the docmd.openform statement:

forms!frmtimecard!employeeID=me.id

hth
--
Maurice Ausum


:

I have an Employee Form and form it I have a command button to open the
subform time card. It does open it but what it does not do is add the
employee # to the Time Card Table.
Here is the code I use to open the sub form.
Private Sub OpenTimeCard_Click()
On Error GoTo Err_OpenTimeCard_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTimeCard"

stLinkCriteria = "[EmployeeID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_OpenTimeCard_Click:
Exit Sub

Err_OpenTimeCard_Click:
MsgBox Err.Description
Resume Exit_OpenTimeCard_Click

End Sub

Thanks
Michelle
 

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