G
Guest
I don't get an error but it also does not update my table!!
This code should create a new record in table: tblQualityProvider then copy
ICNNo into the new record.
(The GetNewID comes from a public function - I pasted it below this code).
Private Sub cmdProv_Click()
Dim gappname As String
Dim lCriteria As String
Dim lICCNNO As String
Dim lRacfid As String
lICCNNO = Me!ICNNo
If MsgBox("Any Message") = vbYes Then
DoCmd.SetWarnings False
Dim lID As Long
lID = GetNewID("tblQualityProvider")
lCriteria = "INSERT INTO tblQualityProvider(ID, ICNNo)"
lCriteria = lCriteria & "SELECT " & lID & " AS ID,
tblQualityData.ICNNo"
lCriteria = lCriteria & "FROM tblQualityData "
lCriteria = lCriteria & "WHERE (((tblQualityData.ICNNo)=" & """"
& lICCNNO & """" & "));"
DoCmd.RunSQL lCriteria
DoCmd.SetWarnings True
DoCmd.GoToRecord , , acNewRec
End If
Forms!frmQualityData.Refresh
Forms!frmQualityData.Visible = True
Exit_cmdProv_Click:
Exit Sub
End Sub
///////////
Public Function GetNewID(tblName As String) As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset(tblName)
If rs.RecordCount > 0 Then
rs.MoveLast
GetNewID = rs.Fields(0) + 1
Else
GetNewID = 0
End If
End Function
/////////
This code should create a new record in table: tblQualityProvider then copy
ICNNo into the new record.
(The GetNewID comes from a public function - I pasted it below this code).
Private Sub cmdProv_Click()
Dim gappname As String
Dim lCriteria As String
Dim lICCNNO As String
Dim lRacfid As String
lICCNNO = Me!ICNNo
If MsgBox("Any Message") = vbYes Then
DoCmd.SetWarnings False
Dim lID As Long
lID = GetNewID("tblQualityProvider")
lCriteria = "INSERT INTO tblQualityProvider(ID, ICNNo)"
lCriteria = lCriteria & "SELECT " & lID & " AS ID,
tblQualityData.ICNNo"
lCriteria = lCriteria & "FROM tblQualityData "
lCriteria = lCriteria & "WHERE (((tblQualityData.ICNNo)=" & """"
& lICCNNO & """" & "));"
DoCmd.RunSQL lCriteria
DoCmd.SetWarnings True
DoCmd.GoToRecord , , acNewRec
End If
Forms!frmQualityData.Refresh
Forms!frmQualityData.Visible = True
Exit_cmdProv_Click:
Exit Sub
End Sub
///////////
Public Function GetNewID(tblName As String) As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset(tblName)
If rs.RecordCount > 0 Then
rs.MoveLast
GetNewID = rs.Fields(0) + 1
Else
GetNewID = 0
End If
End Function
/////////