If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
insert query with fields from a form
i am using access 97. I have a form where i enter data,
after i am done entering data i want to be able to hit a command button and that button fires a query to insert the datafields of the form into a database. My problem is that access doesnt like the insert of the form variable in the insert query's values section. Is there anything i can do to solve this or a web reference that helps me along. thanks |
#2
|
|||
|
|||
Please post the SQL view of the query so we can see how you're trying to do
what you're doing. -- Wayne Morgan Microsoft Access MVP "doug" wrote in message ... i am using access 97. I have a form where i enter data, after i am done entering data i want to be able to hit a command button and that button fires a query to insert the datafields of the form into a database. My problem is that access doesnt like the insert of the form variable in the insert query's values section. Is there anything i can do to solve this or a web reference that helps me along. thanks |
#3
|
|||
|
|||
Have you tried using a main/subform or linked form? Searching help for these
topics may shed some light. CH "doug" wrote: i am using access 97. I have a form where i enter data, after i am done entering data i want to be able to hit a command button and that button fires a query to insert the datafields of the form into a database. My problem is that access doesnt like the insert of the form variable in the insert query's values section. Is there anything i can do to solve this or a web reference that helps me along. thanks |
#4
|
|||
|
|||
the query is
INSERT INTO time_log_table ( [task date], [assoc number], [main items], [sub items], [time], [entry date], notes ) SELECT [Forms]![time_entry_form]!calendar.Value, [Forms]! [time_entry_form]!txtAssocNumber.Value, dlookup("[main item desc]", "main_item_table", "[main item code] = [Forms]![time_entry_form]!cboMainItem.value"), dlookup ("[subitem desc]","[subitems_table]", "[subitem code]= [Forms]![time_entry_form]!cbosubItemsection.value"), [Forms]![time_entry_form]!txtHoursonJob.value, format (now, "mm/dd/yyyy"), [Forms]![time_entry_form]! txtComments.Value; any help would be appreciated -----Original Message----- Please post the SQL view of the query so we can see how you're trying to do what you're doing. -- Wayne Morgan Microsoft Access MVP "doug" wrote in message ... i am using access 97. I have a form where i enter data, after i am done entering data i want to be able to hit a command button and that button fires a query to insert the datafields of the form into a database. My problem is that access doesnt like the insert of the form variable in the insert query's values section. Is there anything i can do to solve this or a web reference that helps me along. thanks . |
#5
|
|||
|
|||
I can see one problem right away. In the criteria of your DLookup
statements, you're not concatenating in the value from the form. For example: dlookup("[main item desc]", "main_item_table", "[main item code] = [Forms]![time_entry_form]!cboMainItem.value") Should be: DLookup("[main item desc]", "main_item_table", "[main item code] = " & [Forms]![time_entry_form]!cboMainItem.value) This would be if the value of cboMainItem is a number. If it is a text value, you would need: DLookup("[main item desc]", "main_item_table", "[main item code] = """ & [Forms]![time_entry_form]!cboMainItem.value & """") Both DLookup statements need this correction. For the field "format(now, "mm/dd/yyyy")", I believe you'll need the parentheses after Now. VBA doesn't require them, but I believer the query will. Also, Since you're only storing the Date, judging by the format, you could use Date instead. Using Date, you could probably drop the format statement also and just use Date. Format(Date(), "mm/dd/yyyy") or Date() To make it easier to read, you should be able to drop the ".Value" on each statement. Value is the default property of the control and so is what will be used if you omit it. However, this shouldn't be causing you a problem. Are the field types you are inserting into the correct data type for the data being inserted? This would be set in the table's design view. -- Wayne Morgan Microsoft Access MVP wrote in message ... the query is INSERT INTO time_log_table ( [task date], [assoc number], [main items], [sub items], [time], [entry date], notes ) SELECT [Forms]![time_entry_form]!calendar.Value, [Forms]! [time_entry_form]!txtAssocNumber.Value, dlookup("[main item desc]", "main_item_table", "[main item code] = [Forms]![time_entry_form]!cboMainItem.value"), dlookup ("[subitem desc]","[subitems_table]", "[subitem code]= [Forms]![time_entry_form]!cbosubItemsection.value"), [Forms]![time_entry_form]!txtHoursonJob.value, format (now, "mm/dd/yyyy"), [Forms]![time_entry_form]! txtComments.Value; |
#6
|
|||
|
|||
i now have as my query
INSERT INTO time_log_table ( [task date], [assoc number], [main items], [sub items], [time], [entry date], notes ) SELECT [Forms]![time_entry_form]!calendar.Value, [Forms]! [time_entry_form]!txtAssocNumber.Value, DLookup("[main item desc]", "main_item_table", "[main item code] = """ & [Forms]![time_entry_form]!cboMainItem.value & """"), DLookup("[sub item desc]", "subitem_table", "[subitem code] = """ & [Forms]![time_entry_form]! cbosubItemsection.value & """"), [Forms]![time_entry_form]! txtHoursonJob.value, format(now(), "mm/dd/yyyy"), [Forms]! [time_entry_form]!txtComments.Value; but still no dice. is there still something wrong? thanks -----Original Message----- I can see one problem right away. In the criteria of your DLookup statements, you're not concatenating in the value from the form. For example: dlookup("[main item desc]", "main_item_table", "[main item code] = [Forms]![time_entry_form]!cboMainItem.value") Should be: DLookup("[main item desc]", "main_item_table", "[main item code] = " & [Forms]![time_entry_form]!cboMainItem.value) This would be if the value of cboMainItem is a number. If it is a text value, you would need: DLookup("[main item desc]", "main_item_table", "[main item code] = """ & [Forms]![time_entry_form]!cboMainItem.value & """") Both DLookup statements need this correction. For the field "format(now, "mm/dd/yyyy")", I believe you'll need the parentheses after Now. VBA doesn't require them, but I believer the query will. Also, Since you're only storing the Date, judging by the format, you could use Date instead. Using Date, you could probably drop the format statement also and just use Date. Format(Date(), "mm/dd/yyyy") or Date() To make it easier to read, you should be able to drop the ".Value" on each statement. Value is the default property of the control and so is what will be used if you omit it. However, this shouldn't be causing you a problem. Are the field types you are inserting into the correct data type for the data being inserted? This would be set in the table's design view. -- Wayne Morgan Microsoft Access MVP wrote in message ... the query is INSERT INTO time_log_table ( [task date], [assoc number], [main items], [sub items], [time], [entry date], notes ) SELECT [Forms]![time_entry_form]!calendar.Value, [Forms]! [time_entry_form]!txtAssocNumber.Value, dlookup("[main item desc]", "main_item_table", "[main item code] = [Forms]![time_entry_form]!cboMainItem.value"), dlookup ("[subitem desc]","[subitems_table]", "[subitem code]= [Forms]![time_entry_form]!cbosubItemsection.value"), [Forms]![time_entry_form]!txtHoursonJob.value, format (now, "mm/dd/yyyy"), [Forms]![time_entry_form]! txtComments.Value; . |
#7
|
|||
|
|||
What is the Data Type of each of the fields you are inserting into? You say
it doesn't work, do you get an error? If so, what's the error? Is this a "stored" query (a query in the query tab of the database window)? If not, where is it located? -- Wayne Morgan MS Access MVP "doug" wrote in message ... i now have as my query INSERT INTO time_log_table ( [task date], [assoc number], [main items], [sub items], [time], [entry date], notes ) SELECT [Forms]![time_entry_form]!calendar.Value, [Forms]! [time_entry_form]!txtAssocNumber.Value, DLookup("[main item desc]", "main_item_table", "[main item code] = """ & [Forms]![time_entry_form]!cboMainItem.value & """"), DLookup("[sub item desc]", "subitem_table", "[subitem code] = """ & [Forms]![time_entry_form]! cbosubItemsection.value & """"), [Forms]![time_entry_form]! txtHoursonJob.value, format(now(), "mm/dd/yyyy"), [Forms]! [time_entry_form]!txtComments.Value; but still no dice. is there still something wrong? |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Query to join records form 2 databases | bdehning | General Discussion | 5 | August 9th, 2004 03:09 PM |
Newbie? Do I use Report or Query | John Egan | New Users | 11 | June 28th, 2004 08:31 PM |
how to combine fields on a form in a query as criteria? | Henro | New Users | 3 | June 8th, 2004 03:50 PM |
Query By Form | Craig | Running & Setting Up Queries | 2 | June 1st, 2004 01:10 AM |
Filter by Form query will not populate fields | Brigitte P | Running & Setting Up Queries | 2 | May 27th, 2004 12:59 PM |