Help with Autofilling fields from one form to the next (1 Viewer)

jdp103

Registered User.
Local time
Today, 04:35
Joined
Sep 26, 2003
Messages
46
I am sure this has been asked a thousand times, but I couldn't seem to find a thread.

I have a form, which contains a subform. When in the subform, I have a button to create a new main form and I want it to prefill in the data from some fields on the subform.

It looks like it should work, but #1, when I am in the main form inside the subform, the botton does nothing. If I open only the subform, then it at least works.

And #2, it definitely captures the values that I want, but it doesn't fill them in on the form.

Here is my code:
Private Sub Command44_Click()
On Error GoTo Err_Command44_Click
Dim doc As String
Static tit As String
Static desc As String
doc = "Business Requirement Document"
title = IssueType
desc = Issue

DoCmd.OpenForm doc, acNormal, , , acFormAdd

BRD_Title = title
BRD_Description = desc

Exit_Command44_Click:
Exit Sub

Err_Command44_Click:
MsgBox Err.Description
Resume Exit_Command44_Click

End Sub

Any help would be MUCH appreciated!!
 

mwn1218

Registered User.
Local time
Today, 04:35
Joined
Jan 26, 2005
Messages
30
Here are some thigns that might help you on your second question.

Declare your variables as Public (do this under the Option Compare Database at the top of the page)
Public doc as string
Public title as string
Public desc as string

or if you want to use these variables on other forms you can create a variable module and declare your variables within there (I have found this helps when passing information from form to form or from form to report).

aslo make sure you spell the names of the variables correctly (Noticed when you declared the title variable you did it as 'tit' and then your code you used 'itle')

then when populating the sub form try
BRD_Desription.Value = desc

Hope that helps
 

jdp103

Registered User.
Local time
Today, 04:35
Joined
Sep 26, 2003
Messages
46
I've fixed the variable names, and I can watch the values get set in the Locals window, but they never show up in the newly opened form. I've made the variables public. I also tried the BRD_Title.value = title, but that didn't work either! Here is my new code:

Option Compare Database
Public doc As String
Public title As String
Public desc As String


Private Sub Command44_Click()
On Error GoTo Err_Command44_Click
doc = "Business Requirement Document"
title = IssueType
desc = Issue

DoCmd.OpenForm doc, acNormal, , , acFormAdd
BRD_Type = "CPR"
BRD_Title = title
BRD_Description = desc


Exit_Command44_Click:
Exit Sub

Err_Command44_Click:
MsgBox Err.Description
Resume Exit_Command44_Click

End Sub
 

mwn1218

Registered User.
Local time
Today, 04:35
Joined
Jan 26, 2005
Messages
30
Instead of trying to set the values here

DoCmd.OpenForm doc, acNormal, , , acFormAdd
BRD_Type = "CPR"
BRD_Title = title
BRD_Description = desc

in the OnLoad event of the form copy this
BRD_Type.text = "CPR"
BRD_Title.value = title
BRD_Description.value = desc

is BRD_Type always going to be CPR?

And if that does not work try creating a module were you declare you variables.
 

jdp103

Registered User.
Local time
Today, 04:35
Joined
Sep 26, 2003
Messages
46
Yes, the BRD_Type will always be CPR if it is entered via this route.

Questions - if I do this in the form OnLoad event will it have an impact if a new record is created using the form by another means?
 

mwn1218

Registered User.
Local time
Today, 04:35
Joined
Jan 26, 2005
Messages
30
Questions - if I do this in the form OnLoad event will it have an impact if a new record is created using the form by another means?
Yes it would affect that. So instead but the code back under the button and try:

forms![formName]!field =

forms![FormName]!BRD_Description = desc

not sure how this will work with text (ie: "CPR") so you can try it like that or try .text = "CPR" or create a variable called CPR = "CPR" and set the field = to the variable CPR.
 

jdp103

Registered User.
Local time
Today, 04:35
Joined
Sep 26, 2003
Messages
46
WOOHOO! That worked! You're the best! Thanks so much for your help!!
 

Users who are viewing this thread

Top Bottom