Query based on subform combobox (1 Viewer)

AndyCompanyZ

Registered User.
Local time
Today, 00:25
Joined
Mar 24, 2011
Messages
223
I am trying to build a query based on a combobox that is on a subform that cascades from a combobox on a main form. So far I have :
INSERT INTO tblSubTeamEvent ( SubTeamID, EventID )
VALUES (Me!SubFormSubTeamForm.Form!cmboSubTeamSF, [Forms]![frmEvent]![EventID]);
but when I run it it asks for the parameter value of the cmboSubTeamSF. If I just ignore the question it still updates the EventID into the table but obviously not the SubTeamID. I've tried various combinations of Me! Forms! etc but can't get it to work any ideas any one
 

spikepl

Eledittingent Beliped
Local time
Today, 01:25
Joined
Nov 3, 2010
Messages
6,142
Open the query in the query designer. In the Criterion row for SubteamID, open the Expression builder and navigate to the combo box in question.
 

AndyCompanyZ

Registered User.
Local time
Today, 00:25
Joined
Mar 24, 2011
Messages
223
Just seen my query wasn't quite right it should be:
INSERT INTO tblSubTeamEvent ( SubTeamID, EventID )
VALUES (Me!SubFormSubTeam.Form!cmboSubTeamSF, [Forms]![frmEvent]![EventID]);
But it still does the same I tried entering a num,ber into the parameter box that pops up and it does insert in the right place so that part of the query is right. I just can't get it to point to the combobox.
 

AndyCompanyZ

Registered User.
Local time
Today, 00:25
Joined
Mar 24, 2011
Messages
223
Thanks I rebuilt the query based on how you suggested so it now says
INSERT INTO tblSubTeamEvent ( SubTeamID, EventID )
VALUES ([Forms]![frmEvent]![SubformSubTeam].[Form]![cmboSubTeamSF], [Forms]![frmEvent]![EventID]);
but I'm getting a validation rule violation now on the update query so I'm guessing the table isn't right though I have Required=No, Indexed =Yes Duplicates OK and the field is number. Ahh as i write this I realise that maybe the combobox is set to the wrong bound column and is trying to insert text as that's what's displayed on the form.
 

AndyCompanyZ

Registered User.
Local time
Today, 00:25
Joined
Mar 24, 2011
Messages
223
The problem was as I suspected the combobox was pointing to the wrong column and although I got a key violation at first I did something and i really can't remember waht and it worked. Not very useful I know but now I'm having a similar problem with another combobox on the same form which I was about to post but will put it here instead.
I have a simple query inserting the result of an unbound combobox into a table. It is only one record and into only one place in the table but is giving me a validation rule violation error. I have checked the field on the table and is set to:
Field Size:Long Integer
Field type:Number
Required:No
Indexed: Duplicates OK
Text Align:General

The combobox is based on a query from another combobox (cascading) and the bound column is set to 0 (but I've tried 1 and 2 which in the first instance gives me a type conversion error which I understand because that column is text and the secong gives me the same violation error which again I undertsand because it's not there). Other than that I can't work it out.
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 19:25
Joined
Jan 23, 2006
Messages
15,408
Have you tried putting in some breakpoints and stepping through the code?
Perhaps you can show us the event code and a description of what you're doing -- and someone could sort it out. But without some code or a copy of the db, it's just guessing.
 

AndyCompanyZ

Registered User.
Local time
Today, 00:25
Joined
Mar 24, 2011
Messages
223
Thanks jdraw the problem seems to be in the query itself as the code stops at the line with the query on it. The query itself is:

INSERT INTO tblEvent ( VenueRoom )
VALUES (Forms!frmEvent![cmboVenueRoom]);

and the code behind is:
Private Sub cmboVenueRoom_AfterUpdate()
DoCmd.OpenQuery "qryVenueRoomSave", acViewNormal, acEdit
End Sub

The query is meant to update the event table with the selected item in the combobox.
 

AndyCompanyZ

Registered User.
Local time
Today, 00:25
Joined
Mar 24, 2011
Messages
223
I have now taken the query out and have posted another problem I'm now having in the forms thread.
 

Users who are viewing this thread

Top Bottom