Insert Rows Into Subform Problem, Help!

Dec 8, 2006

hi i have a main form called "frmMain" that i use for users to add new studentsNumbers txtStudentsNumbers.bound to tblStudents also this form has a combo box called cmbDepartments coming from tblDepartments.

Then a subform which right now it has a combobox called cmbSubDepartments (coming from tblSubDepartments) , this combobox has a rowsource to update everytime someone selects a dept in the main form so it shows the subdepartments belonging to the departments.
Each department has a a set of Subdepartments, also has two texboxes called txtTuitionA, and txtTuitionB.
so in total i have three tables each with the pk id.



what i need is that when a user enters a student number in the main form, select the department where they want to add the student to, then the subform gets automotically populated with all the subdepartments so then the user is forced to enter TuitionA and tuition B to each subdept for that particular students

i tried this...

(in the main form)

Private Sub cmbDepartment_AfterUpdate()
Dim intQty As Integer
Dim i As Integer


If MsgBox("Are you sure you want to add a new tuition plans for this student?", vbYesNo) = vbYes Then
Me.txtStudentID = DMax("StudentID", "tblStudents") + 1 'get New student number 'Add the new row into Main Table tblStudents

intQty= me.cmbSubDepartments.itemdata -1

For i = 1 To intQty - 1
strSQL = "INSERT INTO tblStudent (StudentID, SubDepartmentID) SELECT StudentID, SubDepartmentID FROM tblSubDepartments WHERE SubDepartmentID = " & Forms!frmStudentsTuitions_subform!cmbSubDepartment s & ";"
CurrentDb.Execute strSQL


Next i

Me.frmStudentsTuitions_subform.Requery
Me.frmStudentsTuitions_subform.SetFocus



Else
DoCmd.CancelEvent 'if user choose no in question then undo
DoCmd.Close acForm, Me.Name 'close current form

End If


End Sub


but my subform does not get updated... :-( .

View Replies


ADVERTISEMENT

Trying To Insert Multiple Rows

Nov 13, 2006

I'm trying to insert multiple rows into a table at once, but I'm having problems.

I've tried a syntax like this:

INSERT INTO [TABLE] ( [FIELD1], [FIELD2], [FIELD3] ) VALUES
(( '1', 'A', '1' ),( '2', 'B', '2' ));

..but with no success.


On a site I even found this other way, but with no success either...

INSERT INTO [TABLE]
SELECT '1', 'A', '1'
UNION ALL
SELECT '2', 'B', '2';

Is it possible to insert multiple rows and I'm just missing the syntax, or is it not possible with Access?

View 1 Replies View Related

Insert Multiple Rows

Nov 6, 2006

I am trying to insert multiple rows to a table using the query

insert into rvp (rvp, rvp_name, controller_id)
values (1200, 'rvp1', 10), (1201, 'rvp2', 10)

But I am getting an error "Missing semicolon( at the end of SQL statement" and placing a semicolon at the end isn't helping either. I can insert a single row so column type or primary key isn't a problem.

Here's the table structure,

rvp - number (pk)
rvp_name - text
controller_id - number

Can someone please help me out.

View 3 Replies View Related

Insert Rows Skip Duplicates

Dec 28, 2006

Hello,

I want to copy data from one table to another:
INSERT INTO Table1 (codeid) SELECT codeid FROM Table2 WHERE a=7

it works, but the problem occurs when diplicate entries occur in codeid of Table1 (because is is set to No Duplicates).

As a result no rows are inserted. It's OK, cause that's the way it should be, but I was wondering if there is a way to tell MS Access to skip insertion of values that will cause duplication. So the rows that are ok will be inserted and the ones that cause duplicates will be skipped.

I just don't want to go through the loop and insert row-by-row.

Thank you.

View 2 Replies View Related

Queries :: Insert Blank Rows At Once?

Oct 2, 2013

How to insert x number of empty rows at once in a query? All fields allow null.

Say, if I wanted to "resize" the table to 3000 records...

View 6 Replies View Related

Insert All Rows To Access Database

Oct 6, 2012

I use this vba code to insert data in access database 2007. It's working for one row, but when I try to use for more rows and columns give me "Type mismatch".

Code:
Sub Simple_SQL_Insert_Data()
Dim cn As ADODB.Connection '* Connection String
Dim oCm As ADODB.Command '* Command Object
Dim oWS As Worksheet

[code]...

View 5 Replies View Related

Need To Insert Blank Rows If Record < 1000

Mar 24, 2005

Hello all!

I have a database that needs to post records that are joined from three different sources into a table. The query is done, and I get about 1,489 records out in 4 different states.

What I need to do is make a table with these records. Furthermore, it must be separated by state, whereas if there are less than 1000 records for each state, it must insert blank lines until it reaches then next thousandth (sp?) row (i.e. 1001, 2001, etc.), and then start posting the next state.

For example, AZ has 420 records. There has to be 580 blank lines before the query can start posting the next state, CA. At row 1001, CA starts posting, but there are only 200 records for CA so there must be another 800 blank lines before moving on to CO at row 2001, etc. etc.

Anyone have any ideas on this? Thanks!

View 5 Replies View Related

Queries :: Query To Insert Missing Rows From Another Query / Table

Oct 8, 2013

I am using an Access 2010 DB to keep track of a schedule. Essentially, at least one person needs to be signed up to work for every hour of every day in a week.

Tables:
Days with 7 records
Hours with 24 records
Workers with as many people that sign up to work the different hours
Schedule signifying the worker, day, and hour which are signed up.

As of now i have a query that relates these results and gives me a line detailing the worker/time information for the slots that are signed up for.What I'm TRYING to do is to create a query that gives me BLANK worker info when there is no one signed up for a particular hour.Currently my Schedule table has the following:

WorkerID | DayID | HourID
----------+---------+--------
1 | 5 | 12
4 | 5 | 13
16 | 5 | 15


What I'm looking to do is have this table matched up with another table (or query) that provides every combination of day/hour. When an day/hour combination is skipped, the query will be able to "fill in the blank" with a row. Like this:

WorkerID | DayID | HourID
----------+---------+--------
1 | 5 | 12
4 | 5 | 13
| | 14
16 | 5 | 15

View 2 Replies View Related

Accessing Rows In Subform

Jun 29, 2006

Hi!

I want to access individual rows in a subform (frmOrderdetails (datasheet view)).

The reason for this is that I have a checkbox at the end of each orderline, and user will be able to check individual lines and do a return of these lines.

For now, I have a query to return lines, but the problem is that when there are two lines checked, it'll only return the first one.

Anybody that knows how to obtain this?

:-)

Thank you!

View 6 Replies View Related

Forms :: Limit Number Of Rows In A Subform

Jun 20, 2013

I am looking for a way to limit the number of rows that are added to the subform of a main form. Is there anyway that the allowable number of rows be defined using a field on the main form.

View 3 Replies View Related

How To Refresh Subform In Order To Display All Rows

Sep 27, 2013

I have created a form and a subform from a table.

Initially I created a table with 11 rows. After completion of my project I added an extra of 480 rows to the main table. But the newly added rows are not coming in my subform.

Attached is my project.

Main : Main table (It consists of around 491 rows)
MForm : Main Form (It shows of only 11 records which I was 1st created)

How to refresh my subform inorder to display all the rows.

View 11 Replies View Related

Insert Data Into A Subform

Jul 29, 2015

I have a form with a sub form, on the main form I want the user to select a machine number and then when they have selected it I want to populate the required data into the sub form.

In the sub form I have a field called "Seal" and another called "Quantity" what I require is to get the results from either a query or table and list all the seals & quantities for that machine.

I have a table called "Machine" which has all the machine numbers and also fields called "Seal1", "Seal1Qty","Seal2, "Seal2Qty" all the way to Seal 10.

I do not know how the best way to get this data into the sub form...

View 5 Replies View Related

General :: How To Make Previous Rows Disabled In Subform

May 26, 2013

I want to disable the previous row in the subform the moment I do a new row to prevent the user from editing information other users put before. Is it possible.

View 4 Replies View Related

Modules & VBA :: Highlight Rows In A Subform Datasheet Table

Jan 25, 2015

I have a main form users enter info into then submit, which adds it to the table being displayed in the subform...

One of the options is a "Urgent" tick box, if they tick this box, once it has submitted to the table, i need that row to highlight red...

View 3 Replies View Related

Forms :: Autofill Multiple Rows From One Subform To Second Subgroup

Jul 1, 2014

So I have a master form, with multiple subforms on different tabs within the master form. This form is not used to look up data, just to only enter data in. In one of the tabs, I have a subform in the form of a data table where the person filling it in can put multiple locations of one dealership. In the next tab, I want these loctions to autofill into the next subform on the second tab in the data sheet. If I were to go with the solution of using an unbound textbox on the parent/master form to refernece the first subform and then have the second subform reference the textbox, how would I go about doing this? Just with the expression builder and conrol source? Am I able to autofill multiple rows of data from one subform to the other for one recond?

View 6 Replies View Related

Insert A Line Of Data In A Subform

Jul 11, 2007

Hi,
I have a form which records computer faults reported by users. On this form there is a subform for comment tracking eg. Phoned user, Date/Time. On the next line would be; Informed user to do this, Date/Time and so on. I have a button on my form which I would like to use to automatically put in a line of data. It is an aknowlegde fault button. What it hopefully would do is when you click the button it will automatically put in the date/time in the subform, Then the word "acknowledged" in the comment field, then prompt for the user name ( for the username field).
I am not sure on how to start the command. If i were to do it in the same form then I would just put something like;
me.Date.Value = Date()
me.Comment.value = "Acknowledged"
me.Username.value = "[Prompt]"

As you can see I have two problems though;
1. The data has to be entered in a subform
2. My Prompt I dont think will work.

Does anyone have any ideas?

Kind Regards
Keith

View 1 Replies View Related

Modules & VBA :: Insert Fields From Subform Into Database Using SQL

Mar 8, 2015

I am trying to formulate some code to run an SQL statement but it is not working.

The statement runs from a button on the sub form subOriginForm. Its intention is to collect the values from cboField1 and txtfield2 located on that form and insert them into tblTargetDB - but the whole thing isn't working.

Code:
Private Sub cmdMyButton_Click()
'DoCmd.SetWarnings False
INSERT INTO tblTargetDB ( field1, field2)
VALUES (forms!subOriginForm.cboField1, forms!subOriginform.txtfield2);
DoCmd.SetWarnings True
End Sub

View 4 Replies View Related

How To Insert Subform Data To Specific Table

Oct 1, 2013

I have problem with inserting sub-form data to specific table. i have 2 table and one form.

table A is for DLOOKUP, table B is the table i want my sub-form data to insert in.

my table A have ID,name and class.

my table B have ID and other column.

Table A' ID and Table B' ID is related.

i trying to insert my sub-form to table B instead it insert the data to table A.

View 1 Replies View Related

Forms :: Insert New Data And Show All Records In Subform

Mar 27, 2013

I have a form with a subform. I want to use the main form to insert new data and the subform to show all records that are there. One could say that the after inserting a new record with the fields in the form and save it, it should appear in the subform datasheet view.

Please see attached the sample database..

View 3 Replies View Related

Modules & VBA :: Syntax Error With INSERT Statement And Subform

Mar 13, 2015

I am getting a syntax error on my SQL statement.

On a form I have a sub form containing the field txtGuestID - whose control source is GuestID.

On the main form I have a button that fires the code below.

I am sure I am not referring to the control txtGuestID correctly.

Code:
Private Sub cmdInbound_Transport_Click()
Dim iProductID As Integer
Dim sSQL As String
On Error GoTo cmdInbound_Transport_Err

[Code] ....

View 6 Replies View Related

Queries :: Insert Into Query - Duplicate Records In A Subform To New Form

Jun 4, 2013

I'm trying to duplicate the records in a subform to a new form but keep getting a too few parameters error.

Code:
strSql = "INSERT INTO [OrderDetailT] ( OrderID, ProductID, Quantity, DiscountPercentage ) " & _
"SELECT " & lngID & " As NewOrderID, ProductID, Quantity, DiscountPercentage " & _
"FROM [OrderDetailT] WHERE OrderNumber = " & Me.OrderNumber & ";"

The debug.print comes out as below:

INSERT INTO [OrderDetailT] ( OrderID, ProductID, Quantity, DiscountPercentage ) SELECT 49 As NewOrderID, ProductID, Quantity, DiscountPercentage FROM [OrderDetailT] WHERE OrderT!OrderNumber = 11;

View 4 Replies View Related

Modules & VBA :: Allow User To Select Record From Subform And Add It To Table - Insert Statement

Jun 18, 2013

I have a sub form with staff records on it within a main form. I am trying to allow the user to select a record from the sub form and add it to a table, here is my code which, to me, looks correct. However it gives me an error saying "Syntax error in INSERT INTO"

Code:
Private Sub Command3_Click()
Dim dbs As Database
Dim sqlstr As String
Set dbs = CurrentDb
Forename = Nz(Forms!frm_Capex_Submission!frm_staffSub.Form.shy_forename, "")
Surname = Nz(Forms!frm_Capex_Submission!frm_staffSub.Form.shy_surname, "")

[Code] ....

View 1 Replies View Related

Tables :: Use Insert Into Command To Insert Filepath Into Table That Adds Blank Label

Aug 28, 2014

I am at work, and I have acquired a database that prints labels. They now want the database to be coded so that after certain labels are printed the database will print a blank label. I have the code figured out as a Do While statement in order to print the blank label. The problem I am having is that I am trying to use the Insert Into command to insert the filepath into the table that adds the blank label.

|DoCmd.RunSQL "INSERT INTO Rod_tmakLabels ( Print, [Order] ) SELECT Yes AS Expr1, 'Rods Labels' AS Expr2"|

If I run the above command, it just adds the text "Rods Labels" at the end of the table. Is there anyway with the INSERT INTO command that I can insert the new label between the 2nd and 3rd row and add another row? Or is the command designed only to add a new row to the end? I haven't had any luck searching for this yet.

View 1 Replies View Related

Compare Several Hundred Rows Against Other Rows

Nov 21, 2005

Not sure if what I want to do is possible, or at least possible the way things are set up.

I have a massive table - c. 6 million rows. It contains data along these lines:

Plan#, Item, Price, Description, Colour, Value, Location, etc.

The primary key would be Plan# + Item. Each Plan# has approximately 1,000 Items, and there is only 1 Item per Plan#. There are only a limited number of Items (c. 1500) and all or only some Items might be assigned to the Plan#. All items under each unique ID# belong together, sort of in a set. So this huge table has approx. 6,000 unique sets (based on Plan#).

To add to the confusion, Item A under Plan#1 may have different information (Price, Description, Colour, etc.) from Item A under Plan#2. I know this isn't a great way to set up data but this is what I have to work with.

Over the years it's possible that the exact same combination of Items with identical values might have been set up for multiple Plan#s. What I need to do is find any Plan#s which have the exact same combination of Item, Price, Description, etc. So if Plan#R has 200 rows and Plan#S has 201 rows, it automatically doesn't match. If Plan#R has 200 rows and so does Plan#T, all information in each record must match between the two Plan#s (with the exception obviously of Plan#).

I don't think this is possible, and if it is I am sure it's not going to be easy. So far the best I can do is to come up with finding duplicates on Item, Price, Description, etc. but that's only one record at a time and doesn't tell me if the two Plan#s match.

Any help or suggestions would be much appreciated.

Thanks!!!

View 3 Replies View Related

INSERT Query - Insert New Data Only

Jul 2, 2010

Table TBL_NEWDATA is used to append new data to table TBL_PERSON_ALLOCATIONS.

TBL_NEWDATA { Person_ID, Department_ID }
TBL_PERSON_ALLOCATIONS { Person_ID, Department_ID, ... }

I need to devise a query to append data for a particular Department_ID from TBL_NEWDATA to TBL_PERSON_ALLOCATIONS where that data does not already exist there. i.e. for Department_ID 'Research', I would want to append 'Person_ID', 'Department_ID' (in this case: 'Research') to TBL_PERSON_ALLOCATIONS for any tuples not already held.

INSERT INTO TBL_PERSON_ALLOCATIONS (Person_ID, Department_ID)
SELECT Person_ID, Department_ID
FROM TBL_NEWDATA
WHERE TBL_NEWDATA.Department_ID='Form...'

[code]...

This Query takes a single argument from a control (Forms!Main!IN_Department), and this is the Department_ID to be updated.Is there any way to do this using a single query or will I have to use sub queries? I'd hoped not to as to keep the database as concise as possible.

View 2 Replies View Related

Queries :: Insert Into One To Many PK And FK Insert

Mar 25, 2015

I have a normalized DB with one to many relationships, using Primary and Foreign Keys.

I need to do inserts and maintain the PK/FK relationship, which means when I add a new PK I need to insert that PK as FK in other tables in the same transaction.

How do I do this in Access? SQL Server I use transactions, but I can't lock up the tables in Access like that.

I did a bunch of searching and found nothing, which leads me to believe I am way off in my thinking. Below are the dirty details

I have 2 tables, tblName and tblPhone. 1 name can have many phones.

tblName has PKName. tblPhone has PKPhone, FKName.

I have a form where user enters a new Name and PhoneNumber.

Name gets inserted to tblName, assigned with PKName = 100

Phone should get inserted into tblPhone with PKName.

IE Insert into tblPhone (FKName, PhoneNum) VALUES (100,"212-555-1212").

The dumb way I am doing it now is I insert to tblName, query tblname for the PK, then write to tblPhone. This can't be right.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved