Locking data in a field

S

s.r.grace

I'm stuck! I have this form where if you click the Edit Entity button,
it pops up with the data you specify on the orignal form. From there I
want to make it so you can add a new record under the Entity Name. I
want what was typed in the search field (main form) to this subform's
Entity Name field.
 
G

Guest

Pass the value of the control on the main form to the form which is being
opened as its OpenArgs property:

DoCmd.OpenForm "[YourForm]", OpenArgs:=Me.[YourSearchControl]

In the form which is being opened with the above code set the default value
of the Entity Name control to the value of the form's OpenArgs property if
this is not Null. Do this in the second form's Open event procedure:

If Not IsNull(Me.OpenArgs) Then
Me.[Entity Name].DefaultValue = """" & Me.OpenArgs & """"
End If

Ken Sheridan
Stafford, England
 
S

s.r.grace

I got it in the way you said. Are there any other settings that need to
be changed so it locks it in place? It's doing the same thing. Here's
what's in the Event Procedure for the button:

Private Sub Command22_Click()
On Error GoTo Err_Command22_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "SubForm"

stLinkCriteria = "[Entity Name]=" & "'" & Me![SearchCombo] & "'"

DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit, ,
OpenArgs:=Me.[SearchCombo]

Exit_Command22_Click:
Exit Sub

Err_Command22_Click:
MsgBox Err.Description
Resume Exit_Command22_Click

End Sub

Hope this helps.

Ken said:
Pass the value of the control on the main form to the form which is being
opened as its OpenArgs property:

DoCmd.OpenForm "[YourForm]", OpenArgs:=Me.[YourSearchControl]

In the form which is being opened with the above code set the default value
of the Entity Name control to the value of the form's OpenArgs property if
this is not Null. Do this in the second form's Open event procedure:

If Not IsNull(Me.OpenArgs) Then
Me.[Entity Name].DefaultValue = """" & Me.OpenArgs & """"
End If

Ken Sheridan
Stafford, England

I'm stuck! I have this form where if you click the Edit Entity button,
it pops up with the data you specify on the orignal form. From there I
want to make it so you can add a new record under the Entity Name. I
want what was typed in the search field (main form) to this subform's
Entity Name field.
 
G

Guest

If by 'locks in place' you mean save the record even if no other data is
entered into it you should set the value of the control rather than its
default value if the form is at a new record. Do this in the SubForm form's
Current event procedure rather than its Open event procedure:

If Me.NewRecord Then
Me.[Entity Name] = Me.OpenArgs
End If

By setting the Value property, which is the default property so you don't
need to refer to it specifically, this initiates an Edit of the record, so
that if the form is closed or moves to another record an Update will be
executed, saving the new record. Setting the DefaultValue property on the
other hand does not initiate an Edit, so the record is not saved unless its
otherwise edited.

Note that when you set the Value property you don't have to wrap the value
of the OpenArgs property in literal quotes as you do when setting the
DefaultValue. In fact in most cases its not absolutely necessary to do so
when setting the DefaultValue property, but it can be crucial, one example
being when the field is of date/time data type, where wrapping the value in
quotes is essential. You might think that wrapping it in the usual # date
delimiter character would be the correct way, but that would actually give
the wrong date in many cases when used on non-US date formatted systems (like
mine) if a short date format is used as date literals must be in a US or an
otherwise internationally unambiguous date format; 4 July would become 7
April here!

Ken Sheridan
Stafford, England

I got it in the way you said. Are there any other settings that need to
be changed so it locks it in place? It's doing the same thing. Here's
what's in the Event Procedure for the button:

Private Sub Command22_Click()
On Error GoTo Err_Command22_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "SubForm"

stLinkCriteria = "[Entity Name]=" & "'" & Me![SearchCombo] & "'"

DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit, ,
OpenArgs:=Me.[SearchCombo]

Exit_Command22_Click:
Exit Sub

Err_Command22_Click:
MsgBox Err.Description
Resume Exit_Command22_Click

End Sub

Hope this helps.

Ken said:
Pass the value of the control on the main form to the form which is being
opened as its OpenArgs property:

DoCmd.OpenForm "[YourForm]", OpenArgs:=Me.[YourSearchControl]

In the form which is being opened with the above code set the default value
of the Entity Name control to the value of the form's OpenArgs property if
this is not Null. Do this in the second form's Open event procedure:

If Not IsNull(Me.OpenArgs) Then
Me.[Entity Name].DefaultValue = """" & Me.OpenArgs & """"
End If

Ken Sheridan
Stafford, England

I'm stuck! I have this form where if you click the Edit Entity button,
it pops up with the data you specify on the orignal form. From there I
want to make it so you can add a new record under the Entity Name. I
want what was typed in the search field (main form) to this subform's
Entity Name field.
 
S

s.r.grace

Thanks! That did it! Good to know there are hundreds of solutions to
problems like mine.

Thanks again.

Ken said:
If by 'locks in place' you mean save the record even if no other data is
entered into it you should set the value of the control rather than its
default value if the form is at a new record. Do this in the SubForm form's
Current event procedure rather than its Open event procedure:

If Me.NewRecord Then
Me.[Entity Name] = Me.OpenArgs
End If

By setting the Value property, which is the default property so you don't
need to refer to it specifically, this initiates an Edit of the record, so
that if the form is closed or moves to another record an Update will be
executed, saving the new record. Setting the DefaultValue property on the
other hand does not initiate an Edit, so the record is not saved unless its
otherwise edited.

Note that when you set the Value property you don't have to wrap the value
of the OpenArgs property in literal quotes as you do when setting the
DefaultValue. In fact in most cases its not absolutely necessary to do so
when setting the DefaultValue property, but it can be crucial, one example
being when the field is of date/time data type, where wrapping the value in
quotes is essential. You might think that wrapping it in the usual # date
delimiter character would be the correct way, but that would actually give
the wrong date in many cases when used on non-US date formatted systems (like
mine) if a short date format is used as date literals must be in a US or an
otherwise internationally unambiguous date format; 4 July would become 7
April here!

Ken Sheridan
Stafford, England

I got it in the way you said. Are there any other settings that need to
be changed so it locks it in place? It's doing the same thing. Here's
what's in the Event Procedure for the button:

Private Sub Command22_Click()
On Error GoTo Err_Command22_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "SubForm"

stLinkCriteria = "[Entity Name]=" & "'" & Me![SearchCombo] & "'"

DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit, ,
OpenArgs:=Me.[SearchCombo]

Exit_Command22_Click:
Exit Sub

Err_Command22_Click:
MsgBox Err.Description
Resume Exit_Command22_Click

End Sub

Hope this helps.

Ken said:
Pass the value of the control on the main form to the form which is being
opened as its OpenArgs property:

DoCmd.OpenForm "[YourForm]", OpenArgs:=Me.[YourSearchControl]

In the form which is being opened with the above code set the default value
of the Entity Name control to the value of the form's OpenArgs property if
this is not Null. Do this in the second form's Open event procedure:

If Not IsNull(Me.OpenArgs) Then
Me.[Entity Name].DefaultValue = """" & Me.OpenArgs & """"
End If

Ken Sheridan
Stafford, England

:

I'm stuck! I have this form where if you click the Edit Entity button,
it pops up with the data you specify on the orignal form. From there I
want to make it so you can add a new record under the Entity Name. I
want what was typed in the search field (main form) to this subform's
Entity Name field.
 

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