PDA

View Full Version : Solved: Form vs SubForm or Dialog Box



Imdabaum
06-22-2006, 07:32 AM
:banghead: I Need a solution for one of these options.

1. How can I pass the value of a field from the main form in order to use it in a dialog box?

2. How can I access a Method from the SubForm from the Main form?

OBP
06-22-2006, 11:08 AM
You can either pass the value directly with
msgbox = me.fieldname
or assign it to a variable (string for text or Integer/Double for numerical value) first like this
dim message as string
message = me.fieldname
msgbox message.

I am not sure what you mean by a Method?

Imdabaum
06-22-2006, 02:51 PM
Method is a Sub or a function you right such as Add_Click()

I'm not sure how the msgbox applies. The Main form opens a subform as a dialog box so the user has to hit done/close before they can return to the main form. This is the form that I would like to apply the ID. But I can't refer to the subform from the main form, and I don't know how to refer to the main form from the subform. I'm kind of new at this so I apologize for not understanding everything.

OBP
06-23-2006, 03:26 AM
I thought you meant a message box when you said "use it in a dialog box".
There seems to be some confusion here about a subform as well, a subform is usually open "on" a Main form so that both are visible. They are normally linked by a common field through the Master/Child Link.
Your set up sounds more like the Main form is opening a second form.
Can you post a zipped copy of the database on here?
To refer to a field in a new form as you have described it use the current VBA that opens the form and add the following code
Forms![FormName]![Fieldname] = me.fieldname
where [Formname] is the name of the new form and [Fieldname] is the name of the field that you want to pass the data to.
me.fieldname is the name of the field on the master form.

Imdabaum
06-23-2006, 08:49 AM
**EDITED**
Sorry it does not work. It works on the first record, but when I go to next on the main form it doesn't pass it. I will try again. But if anyone else has some ideas I'm open minded.

Sorry according my contract I am not allowed to distribute copies of the database. Here is the Code that opens the new form though:

Private Sub cmdNewNote_Click()
On Error GoTo Err_cmdNewNote_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "sfrmProjectUpdates"

stLinkCriteria = [Forms]![frmProjectUpdates]![ProjectID]=" & Me![txtID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_cmdNewNote_Click:
Exit Sub
Err_cmdNewNote_Click:
MsgBox Err.Description
Resume Exit_cmdNewNote_Click

End Sub

**UPDATE***
I did get it to work for all of them. By setting the default Value = [Forms]![frmProjectNew]![ProjectID]

so I guess the problem is solved and I'll keep using it as a form instead of the subform.

Edited 24-Jun-06 by geekgirlau. Reason: insert vba tags

OBP
06-23-2006, 11:28 AM
Sorry I missed what you said, when you move to the second record on the mainform it doesn't pass what to what?
Do you close the subform when you move the record and reopen it using your code for the second record.
Is the new form data coming from a different table to the Mainform?
If so what relationship do have set up?
It should be from the main form txtID to the new form's ProjectID with referential integrity enforced giving a 1 to many relationship.

Can you import the table, queries and the 2 forms in to a blank database and delete the data from the table to post on here?

Imdabaum
06-26-2006, 07:20 AM
The main form opens the new form and passes the projectID into the new form. When you are done with the new form you click done and it closes. Then if you switched in the main form to the next record, the new form still showed the projectID for the first record instead of the second.

That's all I was saying, but as I mentioned I was able to fix it by setting the default value to the Main form's projectID field. No need to worry about this issue anymore.

I do appreciate your help. The values you gave me were exactly what I needed in the default value for the new form's ID field.