473,769 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use ADO to insert/update/select data into a form with subform(Datashe et)

1 New Member
Dear all,
I have a question about ADO in the subform. I know how to use ADO to insert/update/select data into the sigin form, but wehn I try to do it in the form with subform((Datash eet). I don't have any idea how to insert/update/select the recordset data into the subform(Datashe et), especially insert/update. Would someone can give me a idea or sample code to me? Appreciate your help.


OS: windows XP +SP2+ Access 2003+SP2
Database: MS SQL Server 2000+SP4
Oct 8 '07 #1
11 3158
nico5038
3,080 Recognized Expert Specialist
The mainform's properties like recordsource can be referenced with the "Me.recordsourc e"
For the subform on such a mainform you need: "Me!<subformnam e>.Form.records ource"

Nic;o)
Oct 8 '07 #2
RobinAG
40 New Member
Hi Nico,

I'm having trouble putting this together.

This is what I've got:
Expand|Select|Wrap|Line Numbers
  1. Me!subFrmTasks.Form.RecordSource = str
And I get this error: Runtime 40036, "Applicatio n-defined or object-defined error".

I also tried with using "Me." instead of "Me!", and I got same error code, "Method 'Form' of object '_SubForm' failed"

Any ideas?
Oct 11 '07 #3
nico5038
3,080 Recognized Expert Specialist
Hmm, make sure that "str" contains a valid SQL Select string and also verify that the name of the subform (See under "Other" tab in properties window) is the name used after the Me!

Nic;o)
Oct 11 '07 #4
RobinAG
40 New Member
I've checked both and they are correct, not sure where else to look, I'll keep searching.

R
Oct 11 '07 #5
nico5038
3,080 Recognized Expert Specialist
Perhaps database corruption is the problem.
Try to create a new blank database and use File/Get externaldata/Import to create a new "fresh" copy of the database.

Nic;o)
Oct 11 '07 #6
RobinAG
40 New Member
OK, so I'm not getting anywhere. This is the last thing I have to do on this database before I leave the company!

I've made a new database, reimporting all the tables, queries, forms and modules necessary. Here is what my whole code looks lik, on the On Open event for the main form:

Expand|Select|Wrap|Line Numbers
  1. str = "SELECT tblTasks.TaskID, tblTasks.ProjectID, tblTasks.NameID, tblTasks.NameID2, tblTasks.TaskTypeID, tblTasks.Notes, tblTasks.LanguageID, tblTasks.WordCount, tblTasks.Email, tblTasks.AssignDateMonth, tblTasks.AssignDateDay, tblTasks.AssignDateYear, tblTasks.DeadlineMonth, tblTasks.DeadlineDay, tblTasks.DeadlineYear, tblTasks.TaskStatusID, tblTasks.NameID2, tblTasks.ProjectManagerID, tblTasks.DateCreated, tblTasks.PostponedFrom, tblName.PersonEmail, tblName_1.PersonEmail, tblTasks.AssignTime, tblTasks.DeadlineTime, tblTasks.StatusID, tblName.NameTypeID, tblName_1.NameTypeID, tblTasks.EmailSent, tblTasks.UnderstandsSource, tblTasks.TechnicalIssues, tblTasks.StyleGuide, tblTasks.PercentComplete, tblTasks.UpdateFlag, tblTasks.VENotes FROM tblName AS tblName_1 RIGHT JOIN (tblTasks LEFT JOIN tblName ON tblTasks.NameID = tblName.NameID) ON tblName_1.NameID = tblTasks.NameID2 ORDER BY tblTasks.LanguageID;"
  2. Me!subfrmTasksOneLine.Form.RecordSource = str
  3. Me!subFrmTasks.Form.RecordSource = str
I've checked the subform names, and it's fine. I've made sure that the subform names are accurate, and that the sql code is functional. The Master-Child relatioship is set on the forms themselves (not in code). The subforms are set in tabs, I don't know if that affects anything. I'm getting two distinct problems.

On the line: Me!subfrmTasksO neLine.Form.Rec ordSource = str, I get nothing, the subform comes up without a recordset (the unpopular #Name?). This is my first time setting a subform recordset through code, so it could be I'm missing something fundamental.

On the next line: Me!subFrmTasks. Form.RecordSour ce = str, I get the same error as before, "Applicatio n-defined or object-defined error". The only difference between these two subforms is that they are put in a tab; subFrmTasks is in the hidden tab. I don't know if that could affect things.
Oct 12 '07 #7
nico5038
3,080 Recognized Expert Specialist
Hmm, looks like the event sequence isn't working OK.
You could try to move the code into the OnCurrent event of the form, that way we're sure that the subforms are loaded.

I'm puzzled why you are setting the recordsource here, as I see no variable part in the query. Why not have the subforms with a "fixed" recordsource ?

Nic;o)
Oct 12 '07 #8
RobinAG
40 New Member
The main form is a project form that opens up from a separate form. Depending on what the Project ID is, these subforms are based off of a different recordsource. I actually didn't post the two recordsource strings, to keep the posting simple.
Oct 12 '07 #9
nico5038
3,080 Recognized Expert Specialist
Did the move to the OnCurrent event work ?

Nic;o)
Oct 12 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
9111
by: deko | last post by:
I have a form with a subform datasheet - I need code behind the OnDelete event of the subform: Private Sub Form_Delete(Cancel As Integer) 'do something that depends on which record is deleted End Sub This works okay when only one record is selected and the delete key is pressed (or right-click delete is selected - makes no difference). But if multiple records are selected in the datasheet, the code runs for the first
2
3063
by: deko | last post by:
I'd like to be able to do in-cell editing of a datasheet and have other fields automatically update. I know... the easy answer is to use Excel, but I'm wondering if I can pull this off in Access since all my data is in tables. For example, I have a SubForm Datasheet with these text boxes: txtAccountNumber txtCurrentBalance txtPendingTransactions txtLedgerBalance
1
4262
by: ANSWER | last post by:
I have main form who contains subform in datasheet. I want to disable (selecting one column and then Ctrl + C). I just want them to see results in datasheet but not to copy data form datasheet. Thanks in advance
4
3299
by: cefrancke | last post by:
How does Stephen Lebans make the datasheet row color change by clicking a row's check box field? I cant find any code associated with the form, and I cant tell if you have created a class on the form or not, or even "sub classed" the form or check box. Is there a dll that was pre-loaded? All I can do is guess....
1
2733
by: sofakingfree | last post by:
Is there a way to perform actions on the selected records of a datasheet subform? Actually I know it can be done from a pulldown menu or a toolbar. But how can you create a button on the form that will do the same thing? My problem is that every time you select something on the datasheet when you click a button or any control you will lose the selection. Is there anyway to prevent that? I'd rather create a button than try to manage...
1
6724
by: icenemesis | last post by:
I have a form that searches dynamically based on what criteria the user enters. The resulting query populates a subform in datasheet view. If I wanted to have a button that would export the results of the query that is the source for that datasheet form to excel. How would I go about doing that through VBA? Thanks in advance.
15
3720
by: HyBry | last post by:
I have send mail button assigned to datasheet in subform. Works fine if I want to send mail to one person, but I want it to work if I have multiple selection as well. code I have now is FollowHyperlink "mailto:" & Form!list_1_subform3!
1
2206
by: RamanS | last post by:
Hi, I am creating an inventory management database. I have three tables in this database, Products, Orders and Order Details. I have a form Order Entry in which i create an order to be shipped to a client. This form is created using a query that combines all fields of Orders and Order Details table. The upper part of the order entry form is used to enter basic information such as the order date, client name, address etc.
2
4016
by: nomvula | last post by:
hi guys i need some help to duplicate records on my form datasheet: here's the example of my form results: ClientLookup DateCaptured ForecastDate Description ForecastQuantity Forecast Actual UJ 18-Apr-08 01-Mar-08 Fees: Asset 1 R 31,200.00 R 31,200.00 NMBM 22-Apr-08 23-Mar-08 P-MI (E) 07/2006 3 R 47,485 R 38,849 i have 200 records deplayed in the form i'm using access2007 and i have a command button which is the built in command button to...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.