Need Example

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to execute an SQL statement to create a record in tblVersion with foreign key = primary key in tblPeopl
I have the following code, I need to know how to execute the SQL (provided I created it correctly
I have 6 books and none of them address this
Dim lngPeoID As Integer 'holds newly created person ID for tblVersion and tblEva
Dim sSQL As String ' holds query to add the new person's first version recor
DoCmd.RunCommand acCmdSaveRecord 'saves person record so it's ID is create
'create records for tblVersion and tblEvaluatio
'DMax("[FieldName]", "TableName", Optional Criteria if needed
lngPeoID = DMax("[peoPeopleID]", "tblPeople"
'sSQL = "Insert Into tblb (<ForeignKeyFieldName>) Values (" & lngaID & ")
sSQL = "Insert into tblVersion (peoPeopleID Values (" & lngPeoID & ")
DoCmd.Requery sSQ
 
Dim lngPeoID As Integer 'holds newly created person ID for tblVersion and
tblEval
Dim sSQL As String ' holds query to add the new person's first version
record

DoCmd.RunCommand acCmdSaveRecord 'saves person record so it's ID is created

'create records for tblVersion and tblEvaluation
lngPeoID = DMax("[peoPeopleID]", "tblPeople")

sSQL = "Insert into tblVersion (peoPeopleID Values (" & lngPeoID & ")"

CurerntDB.execute sSQL


--
Kipp Woodard



Desert Bear said:
I am trying to execute an SQL statement to create a record in tblVersion
with foreign key = primary key in tblPeople
I have the following code, I need to know how to execute the SQL (provided I created it correctly)
I have 6 books and none of them address this!
Dim lngPeoID As Integer 'holds newly created person ID for tblVersion and tblEval
Dim sSQL As String ' holds query to add the new person's first version record
DoCmd.RunCommand acCmdSaveRecord 'saves person record so it's ID is created
'create records for tblVersion and tblEvaluation
'DMax("[FieldName]", "TableName", Optional Criteria if needed)
lngPeoID = DMax("[peoPeopleID]", "tblPeople")
'sSQL = "Insert Into tblb (<ForeignKeyFieldName>) Values (" & lngaID & ")"
sSQL = "Insert into tblVersion (peoPeopleID Values (" & lngPeoID & ")"
DoCmd.Requery sSQL
 
I've tested your suggested code.
Access takes exception to
sSQL = "Insert into tblVersion (peoPeopleID Values (" & lngPeoID & ")"

I tried adding square brackets:
sSQL = "Insert into tblVersion ([peoPeopleID] Values (" & lngPeoID & ")"
and got the same error

The solution is probably simple.....
 
Back
Top