DblClick Event

B

blazerklk

I'm new to Access, what am I doing wrong passing these variables to the
mainform? I need these pasted or set to the control value in the mainform.
Any help would be appreciated. Thanks

Private Sub Recording_DblClick(Cancel As Integer)

Dim rstInst As Recordset
Dim strRecording As String
Dim strInstDate As String

'Set recordset to Inst table
Set rstInst = dbsCurrent.OpenRecordset("Inst", dbOpenSnapshot)
' Get Recording from subform and set to varible
strRecording = Forms!Ownership![Inst Subform].Form![Recording]
' Get InstDate from subform and set to varible
strInstDate = Forms!Ownership![Inst Subform].Form![InstDate]
Forms!Ownership!Recording.SetFocus
' Set varible to Recording in mainform
Forms!Ownership![Recording] = strRecording 'This Varible has no value
' Set varible to InstDate in mainform
Forms!Ownership![InstDate] = strInstDate 'This Varible has no value
' Cleanup
rstInst.Close

End Sub
 
R

Rick Brandt

blazerklk said:
I'm new to Access, what am I doing wrong passing these variables to
the mainform? I need these pasted or set to the control value in the
mainform. Any help would be appreciated. Thanks

Private Sub Recording_DblClick(Cancel As Integer)

Dim rstInst As Recordset
Dim strRecording As String
Dim strInstDate As String

Set rstInst = dbsCurrent.OpenRecordset("Inst", dbOpenSnapshot)
strRecording = Forms!Ownership![Inst Subform].Form![Recording]
strInstDate = Forms!Ownership![Inst Subform].Form![InstDate]
Forms!Ownership!Recording.SetFocus
Forms!Ownership![Recording] = strRecording 'This Varible has no value
Forms!Ownership![InstDate] = strInstDate 'This Varible has no value
rstInst.Close

End Sub

Why are you opening and closing a Recordset? You are never using it.

Do you get errors when this runs or just no values being set?

Is "Inst Subform" the name of the subform *control* as well as the name of the
form it contains? The control usually has the same name, but that it not
guaranteed and it is the name of the control that the syntax requires, not the
name of the form.
 
B

blazerklk

I guess there is no need to open the recordset.
I'm not setting any values to the varibles strRecording or strInstDate.
The control on the subform is named "Inst Subform", the actual form itself
is OwnershipSubform.
The Forms!Ownership![Inst Subform].Form![Recording] and
Forms!Ownership![Inst Subform].Form![InstDate] both return the values but
don't set the varibles.
I simply want to copy these two field values to the mainform and there is
probably an easier way.
Thanks for the reply Rick your help is appreciated.

Rick Brandt said:
blazerklk said:
I'm new to Access, what am I doing wrong passing these variables to
the mainform? I need these pasted or set to the control value in the
mainform. Any help would be appreciated. Thanks

Private Sub Recording_DblClick(Cancel As Integer)

Dim rstInst As Recordset
Dim strRecording As String
Dim strInstDate As String

Set rstInst = dbsCurrent.OpenRecordset("Inst", dbOpenSnapshot)
strRecording = Forms!Ownership![Inst Subform].Form![Recording]
strInstDate = Forms!Ownership![Inst Subform].Form![InstDate]
Forms!Ownership!Recording.SetFocus
Forms!Ownership![Recording] = strRecording 'This Varible has no value
Forms!Ownership![InstDate] = strInstDate 'This Varible has no value
rstInst.Close

End Sub

Why are you opening and closing a Recordset? You are never using it.

Do you get errors when this runs or just no values being set?

Is "Inst Subform" the name of the subform *control* as well as the name of the
form it contains? The control usually has the same name, but that it not
guaranteed and it is the name of the control that the syntax requires, not the
name of the form.
 
R

Rick Brandt

blazerklk said:
I guess there is no need to open the recordset.
I'm not setting any values to the varibles strRecording or
strInstDate. The control on the subform is named "Inst Subform", the
actual form itself is OwnershipSubform.
The Forms!Ownership![Inst Subform].Form![Recording] and
Forms!Ownership![Inst Subform].Form![InstDate] both return the values
but don't set the varibles.

I don't see how that is possible. If those references return values then either
your variables will be set to match them or you will get an error.
I simply want to copy these two field values to the mainform and
there is probably an easier way.
Thanks for the reply Rick your help is appreciated.

All you should need is...

Forms!Ownership![Recording] = Forms!Ownership![Inst Subform].Form![Recording]
Forms!Ownership![InstDate] = Forms!Ownership![Inst Subform].Form![InstDate]

....and if you run that code from the Ownership form's module that can be reduced
to...

Me![Recording] = Me![Inst Subform].Form![Recording]
Me![InstDate] = Me![Inst Subform].Form![InstDate]

Note that if InstDate is actually a DateTime type then using a string variable
to hold that would not be correct and might have been part of your problem. I
should also point out that copying values from a subform to the main form like
this is very unusual and suggests that your design is incorrect. Normally the
only values that are common between main form and subform are those that are
specified in the MasterLink and ChildLink properties and those are synchronized
automatically.
 
B

blazerklk

Rick many thanks, your great. I knew I was doing it
wrong and re-thought the problem. Thanks again.
Rick Brandt said:
blazerklk said:
I guess there is no need to open the recordset.
I'm not setting any values to the varibles strRecording or
strInstDate. The control on the subform is named "Inst Subform", the
actual form itself is OwnershipSubform.
The Forms!Ownership![Inst Subform].Form![Recording] and
Forms!Ownership![Inst Subform].Form![InstDate] both return the values
but don't set the varibles.

I don't see how that is possible. If those references return values then either
your variables will be set to match them or you will get an error.
I simply want to copy these two field values to the mainform and
there is probably an easier way.
Thanks for the reply Rick your help is appreciated.

All you should need is...

Forms!Ownership![Recording] = Forms!Ownership![Inst Subform].Form![Recording]
Forms!Ownership![InstDate] = Forms!Ownership![Inst Subform].Form![InstDate]

....and if you run that code from the Ownership form's module that can be reduced
to...

Me![Recording] = Me![Inst Subform].Form![Recording]
Me![InstDate] = Me![Inst Subform].Form![InstDate]

Note that if InstDate is actually a DateTime type then using a string variable
to hold that would not be correct and might have been part of your problem. I
should also point out that copying values from a subform to the main form like
this is very unusual and suggests that your design is incorrect. Normally the
only values that are common between main form and subform are those that are
specified in the MasterLink and ChildLink properties and those are synchronized
automatically.
 

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