add existing field to form vba

Gregorys05

Board Regular
Joined
Sep 24, 2008
Messages
217
Hi guys,
I have the below code but am getting a bit stuck.

Form1 is a normal form & form2 is a datasheet form

i think i know what the issue is but cannot find a VBA solution.

the forms load fine and the datasheet has the 4000 odd records but dosen't display any of the data, when i access form2 manually i have to add the Meter_Serial_Number field to the form first before it shows the data.

How would i do this with VBA.

The reason i want this is that i want to have one form and a sub form for all the querys i want to display in my DB this way i dont have stupid number of forms one for each report.

Thank you

Code:
Private Sub cmdviewinByboxnotindhl_Click()
DoCmd.OpenForm "Form1", acNormal, "", "", , acNormal
Forms!form1.Form2.Form.RecordSource = "SELECT TblBybox_Returns_CSV.Meter_Serial_Number" & _
" FROM TblBybox_Returns_CSV LEFT JOIN TblDHL_Returns_CSV ON TblBybox_Returns_CSV.Meter_Serial_Number = TblDHL_Returns_CSV.Mtr_Serial_Number" & _
" WHERE (((TblDHL_Returns_CSV.Mtr_Serial_Number) Is Null));"
Forms!form1.Form2.Form.Requery
Forms!form1.Form2.Form.Refresh
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,216,075
Messages
6,128,665
Members
449,462
Latest member
Chislobog

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top