autopopulate fields on FormB with data from FormA

CBG2112

Registered User.
Local time
Today, 13:48
Joined
Aug 4, 2009
Messages
32
I would like to autopopulate and display data on some fields of FormB when the user presses btnAddRec on Form A. The data will be coming from FormA. I have added code below on the OnLoad event of FormB but it does not work. I only want these fields to be autopopulated when it's a new record. Thanks.

Code:
Private Sub Form_Load()

txtRelatedTo.SetFocus
If IsNull([txtRelatedTo]) Then
    Me![txtRelatedTo] = Forms![frmTaskDetail]![TaskID]
End If
cboSTPriorityNum.SetFocus
if IsNull([cboSTPriorityNUm]) Then
    Me![cboSTPriorityNum] = Forms![frmTaskDetail]![Text6]
End Sub
.
 
You can test with:

If Me.NewRecord Then
 
I can only find this being mostly related to my question and not sure if this is solved?

I have Form1 which is a customers form which has a subform with a list of devices (populated from the devices table)

My question is, from my customers form, I want to be able to create a new entry for the devices table. - i also want the customer id to already be selected in the device form. any chance for an example code?
 
You shouldn't need code. If the master/child link properties of the subform control are set to that field, it will populate automatically.
 
ok i think ive confused you. Basically, on the customers form, if i double click the device in the subform, I can go to that device in the device form.

I want an extra button that opens and creates a new entry in the devices table pre populated with the customer id. Sample code anyone?
 
DoCmd.OpenForm "SecondFormName"...
Forms!SecondFormName.CustomerID = Me.CustomerID
 
DoCmd.OpenForm "SecondFormName"...
Forms!SecondFormName.CustomerID = Me.CustomerID

thanks, but when i run that, it errors, the debug shows the yellow highlight on the second line.

When I mouse over it, it tells me the query responds with the correct ID (29) which relates to the double clicked record, so why will it error?
 
Are all the form and control names correct? If so, you might need to add

DoEvents

between those two lines to give the form time to open.
 
I get an "unrecognized database format.." error on that with 2007. Can you try again, or convert a copy to a lower version?

I love that quote. I'm going to use it on a buddy who's IT Director at the university. It seems like all he does is have meetings all day long. :rolleyes:
 
I get an "unrecognized database format.." error on that with 2007. Can you try again, or convert a copy to a lower version?
Yea sure, here it is matey

I love that quote. I'm going to use it on a buddy who's IT Director at the university. It seems like all he does is have meetings all day long. :rolleyes:
It was like that in my previous job, we spent more time in meetings than doing the damn work! We kept getting "we will have to organise a meeting as its not within the scope of this one"...bloody project managers! << (Sorry if that offends anyone lol)
 

Attachments

For starters you have the forms reversed, it's

Target = Source

Secondly, you are referring to device ID instead of customer ID. Device ID is an autonumber so you can't set it anyway. Thirdly you weren't opening the form in add mode. See if this does what you want:

DoCmd.OpenForm "Devices", , , , acFormAdd
Forms!Devices.CustomerID = Me.CustomerID
 
For starters you have the forms reversed, it's

Target = Source

Secondly, you are referring to device ID instead of customer ID. Device ID is an autonumber so you can't set it anyway. Thirdly you weren't opening the form in add mode. See if this does what you want:

DoCmd.OpenForm "Devices", , , , acFormAdd
Forms!Devices.CustomerID = Me.CustomerID
I ahve it so when adding a new device the customer id is in there. not a problem.

What I want now is the double_click feature to go to the record i double clicked...
 
Happy to help. Now head for a pub!! :p
 

Users who are viewing this thread

Back
Top Bottom