G
Guest
I'm trying to copy data to a new table.
My command botton code grabs the data, creates a new record in the
destination table and dumps it in. It reads a public function called
"GetNewID" to create a new record.
I'm having a problem defining a place for the data.
Here is both the public function and the command button code:
Public Function GetNewID(tblName As String) As Long
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset(tblName)
' Set rs = HoldData
If rs.RecordCount > 0 Then
rs.MoveLast
GetNewID = rs.Fields(0) + 1
Else
GetNewID = 0
/////////////
Private Sub ThankYou_Click()
Dim lCriteria As String
Dim lICCNNO As String
lICCNNO = Me!ICNNo
Dim lID As Long
lID = GetNewID("tblLetterVals")
lCriteria = "INSERT INTO tblLetterVals (ID, ICNNo, ProvNo)"
lCriteria = lCriteria & "SELECT " & lID & " AS ID,
tblQualityData.ICNNo, tblQualityData.ProvNo "
lCriteria = lCriteria & "FROM tblQualityData "
lCriteria = lCriteria & "WHERE (((tblQualityData.ICNNo)=" & """"
& lICCNNO & """" & "));"
DoCmd.RunSQL lCriteria
'Debug.Print lCriteria
DoCmd.SetWarnings True
DoCmd.GoToRecord , , acNewRec
My command botton code grabs the data, creates a new record in the
destination table and dumps it in. It reads a public function called
"GetNewID" to create a new record.
I'm having a problem defining a place for the data.
Here is both the public function and the command button code:
Public Function GetNewID(tblName As String) As Long
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset(tblName)
' Set rs = HoldData
If rs.RecordCount > 0 Then
rs.MoveLast
GetNewID = rs.Fields(0) + 1
Else
GetNewID = 0
/////////////
Private Sub ThankYou_Click()
Dim lCriteria As String
Dim lICCNNO As String
lICCNNO = Me!ICNNo
Dim lID As Long
lID = GetNewID("tblLetterVals")
lCriteria = "INSERT INTO tblLetterVals (ID, ICNNo, ProvNo)"
lCriteria = lCriteria & "SELECT " & lID & " AS ID,
tblQualityData.ICNNo, tblQualityData.ProvNo "
lCriteria = lCriteria & "FROM tblQualityData "
lCriteria = lCriteria & "WHERE (((tblQualityData.ICNNo)=" & """"
& lICCNNO & """" & "));"
DoCmd.RunSQL lCriteria
'Debug.Print lCriteria
DoCmd.SetWarnings True
DoCmd.GoToRecord , , acNewRec