SQL INSERT help (SELECT statement with inputted values)

  • Thread starter Thread starter xFiver
  • Start date Start date
X

xFiver

Hi,

I'm wondering if there's a way to construct an SQL INSERT statement
that will not only grab the records through a SELECT statement, but
will also include a specific value for all records inserted?

I want to populate a table and then add the same date (as entered by
the user in a textbox) for all inserted records.

Any suggestions?
 
I think I'm good! Now... I just had to stumble on a piece of SQL code
to figure it out.

For those searching, the SQL would look like this:

strSQL = "INSERT INTO URKIDS_ATTENDANCE (URKIDSID, GROUPID, CLASS_DATE)
"
strSQL = strSQL & "SELECT URKIDS_GROUP_ASSIGN.URKIDSID,
URKIDS_GROUP_ASSIGN.GROUPID, " & Me.txtDateofClass.Value & " "
strSQL = strSQL & "FROM URKIDS_GROUP RIGHT JOIN URKIDS_GROUP_ASSIGN ON
URKIDS_GROUP.ID = URKIDS_GROUP_ASSIGN.GROUPID "
strSQL = strSQL & "WHERE (((URKIDS_GROUP.SEASON)= " & intSeason & ")
AND ((URKIDS_GROUP_ASSIGN.GROUPID) = " & intGroupID & "));"
 
If I'm reading this correctly, you want to have a constant value as
part of a Select query that is inserting records in an Insert query.
Here's how:

Docmd.RunSQL "Insert into TableName(Field1, Field2, DateField) " & _
"Select Field1, Field2, '" & Me.DateFieldName & "' " & _
"From Table2Name " & _
"Where ......"

Hope that helps!
 
Back
Top