473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Adding records through Subform

I've got myself a bit mixed up with all my sqls and subforms. I am a bit new to relationship databases.

I have a database designed for booking students on to courses run at our hospice. It is based on three main tables. [tblCourselist], [tblStudentinformation] and a table to link these [tbleLINKStudent_Course].

I have a form [frmStudentCourseRecord] based on [tblStudentinformation] with a subform based on an SQL query which i have listed below. This shows the details of the course(s) the student is registered on or have been on previously:

Expand|Select|Wrap|Line Numbers
  1. SELECT tblLINKStudent_Course.lngStudentID, tblLINKStudent_Course.lngCourseID, tblLINKStudent_Course.Courseattended, tblLINKStudent_Course.CoursePaid, tblLINKStudent_Course.CourseComplete, tblLINKStudent_Course.Heardaboutcourse, tblLINKStudent_Course.CourseInfoSent, tblLINKStudent_Course.MemNotes, tblLINKStudent_Course.DateBooked, tblLINKStudent_Course.BookedBy, tblCourselist.lngCourseID, tblCourselist.strCourseTitle, tblCourselist.curCourseCost, tblCourselist.strLunchProvided, tblCourselist.memNotes, tblCourselist.CourseDate, tblLINKStudent_Course.PaidBy, tblLINKStudent_Course.strDietryRequ, tblLINKStudent_Course.[Booking Reference]
  2. FROM tblCourselist INNER JOIN tblLINKStudent_Course ON tblCourselist.lngCourseID = tblLINKStudent_Course.lngCourseID
  3. ORDER BY tblLINKStudent_Course.DateBooked DESC;
Not sure if this is the best way to display the code.

THE PROBLEM:

I want to be able to enrole a student on a new course so that once registered, the details will be recorded on the subform, which is based on my sql query, for that individual. The table [tblCourseList] contains all the courses run at the hospice, with all the relevant fields [curCourseCost] etc.

WHAT I HAVE TRIED:
I have placed a control button in the subform with a macro to open a new form which is a copy of the subform, remaned as [frmAddCourseForStudent] so it is stll based on the sql query above. I thought changing the field [strCourseTitle] to a combobox would allow me to select the right course and bobs your uncle. My mistake! The control source for this field is set as [tblCourseList] so i removed this and set the record source as a sql query [tblCourseList]SELECT [strCourseTitle]. This brings up list of courses in the field but nothing else.

I want to be able to select the course in this form, which then populates all the other linked fields like [curCourseCost] from [tblCourseList] so that when form [frmStudentCourseRecord] is opened for an individual student it will show all the courses enroled in in the subform with the newley added course.

Sorry for the long winded explanation but can anybody help me untangle my SQLs forms?

Thanks
Oct 29 '07 #1
11 1944
NeoPa
32,556 Expert Mod 16PB
You have (accidentally) posted this question in the Access Articles section. This is NOT an article.
I'm moving this to the main Access questions forum.

ADMIN.
Oct 29 '07 #2
NeoPa
32,556 Expert Mod 16PB
I'm not too hot on using forms like this, but (Example Filtering on a Form.) may help you from what I understand of your needs.
PS when posting code, the easy way to do it is to select all your code in a chunk, then click on the hash (#) button. This will add the code tags for you :)
Oct 29 '07 #3
Thanks for that. I have had a look at the code but will need some time to understand it.

Thanks
Oct 29 '07 #4
NeoPa
32,556 Expert Mod 16PB
Take your time.
This is a really useful concept once you get it :)
Oct 29 '07 #5
I have had a good look at the Form Filtering databased which is zipped on this thread. I have very little knowledge of VBA but could the code be cut down so that it filtered on just one control, e .g. CourseTitle but then place the returned values from the filter in a new form as a new record? If so, how

Not sure that explains my question very well. Would a copy of the database help to see where my question is coming from?
Nov 5 '07 #6
NeoPa
32,556 Expert Mod 16PB
I found your other post and was working on it when you reposted it in here. Quite funny really :D
I deleted all remnants of it now so we can continue in here as if it never happened.
Nov 5 '07 #7
NeoPa
32,556 Expert Mod 16PB
I have had a good look at the Form Filtering databased which is zipped on this thread. I have very little knowledge of VBA but could the code be cut down so that it filtered on just one control, e .g. CourseTitle but then place the returned values from the filter in a new form as a new record? If so, how

Not sure that explains my question very well. Would a copy of the database help to see where my question is coming from?
In answer to your question, No.
Some of the principles may be the same but you're asking about a separate aspect here really.

Filtering simply selects, from the available records, those that match a particular criteria. It does not set defaults for the controls on a form for when you add a new record. In other words - A filtered form will NOT restrict addition of new records to the filtered criteria.

This can be done, but with some extra code in your form to set defaults on the fly to those matching your criteria. Make sure to set the Control defaults rather than trying to change the defaults for the underlying Field in the table.
Nov 5 '07 #8
A shame nothing in life is quite so simple.
When you say a little extra code, what are we talking? For a complete novice like myself could you point me in the right direction with the code or do you have any sample code i could tweak?

Cheers
Nov 5 '07 #9
NeoPa
32,556 Expert Mod 16PB
Let me see if I can dig something up for you.
I don't know where it is at the moment but I'll see what I can find. Hopefully it's a work database that I did this on.
Nov 6 '07 #10
That would be great. My knowleddge of databases is slowly growing with each database but with this seems to bring the need to build something more elaborate!
Nov 6 '07 #11
NeoPa
32,556 Expert Mod 16PB
Try this :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     Dim strJob As String, strDefault As String
  3.  
  4.     With Me
  5.         strJob = ""
  6.         If .Filter > "" Then strJob = Split(.Filter, "'")(1)
  7.         .Caption = Replace(.Caption, "%J", strJob)
  8.         .lblTitle.Caption = Replace(.lblTitle.Caption, "%J", strJob)
  9.         .txtJob.DefaultValue = "'" & strJob & "'"
  10.         strDefault = Replace("#31 Dec %Y#", "%Y", Year(Date + 5))
  11.         .txtExpiry.DefaultValue = IIf(strJob = "Mgmt", strDefault, "")
  12.         .lblExpiry.Visible = (strJob <> "ElecInv")
  13.         .txtExpiry.Visible = .lblExpiry.Visible
  14.     End With
  15. End Sub
It's original so not doctored for this purpose so you'll see extraneous code in there too. I've underlined the main lines that you're interested in though.
It works from the Me.Filter property and sets up defaults for two fields depending on what it finds there.
Nov 6 '07 #12

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

Similar topics

2
by: Dee | last post by:
I have a form which contains basics of a customer's order from table . I placed a tab control on this form which is still empty. I'm trying to design a project management database and would like...
1
by: Andante.in.Blue | last post by:
Hi everyone! In Access 97, I have a parent form and a subform that are both based on the same query. The main form is continuous and serves up a summary for each record. The subform provides...
6
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new...
6
by: Wendy Powley | last post by:
I have a subform which represents a 1:N relationship with the main form. I would like to be able to read values from an external file, fill the subform with the values read & allow the user to...
7
by: Ron | last post by:
Hi All, Using Access2000, winXP. Table 1 = tblClients displayed on frmClients via qryClients. 2nd table = tblInvoices shown on frmInvoices via qryInvoices. 2nd table = tblDetails shown on...
3
by: john | last post by:
In my form (table A) I have subform (table B (only 2 fieds: ID and App_name) where table A -Table B are linked 1XM. To be able to add a record in the subform I want to use a lookup form since the...
0
by: vljones | last post by:
Hoping to find a way of entering new data into a combo box which contains a list of items contained in a table. In addition I want to allocate an ID number to entries that are not currently in...
0
by: Richnep | last post by:
Hi all,. I have a small issue I would like to resolve with VBA. I have a form which it's fields are bound to a table. Within that form is a subform which is a subtable. Tables relationship...
2
by: altesse33 | last post by:
I have a command button on the main form of my database that allows users to add new records. But, even though new records get added to the sub table when I click on the button, those new records...
3
by: ramprat | last post by:
Hi All, I am using Access 2003 and have a continuous form based on a table (table1) as a subform on another form. I simply want to be able to take any records that get added to table1 through the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.