I have a form that contains a Software_ID, Software, Version, Install_Date that is tied to the Tag field. This form uses fields from the tblSoftware table and the tblHardwareSoftware table. Then, I have a button that adds the fields Software and Version from the lktblStandardSoftware table. I have gotten the code to add all the data from the lktblStandardSoftware table to the other two tables, but now I want to make sure that the data will only be added once per tag number.
This is the code that I have at this moment:
Private Sub btnStandardSoftware_Click()
Dim rst1 As ADODB.Recordset
Dim rst2 As ADODB.Recordset
Dim rsCheckHardwareSoftwareForDups As ADODB.Recordset
Dim strSQL As String
strSQL = "SELECT tblHardwareSoftware.Tag "
strSQL = strSQL & "FROM tblHardwareSoftware "
strSQL = strSQL & "WHERE (tblHardwareSoftware.Tag=[Forms]![frmmain]![txtTag]);"
On Error GoTo Err_btnStandardSoftware_Click
Set rst1 = New ADODB.Recordset
Set rst2 = New ADODB.Recordset
Set rsCheckHardwareSoftwareForDups = New ADODB.Recordset
rst1.ActiveConnection = CurrentProject.connection
rst2.ActiveConnection = CurrentProject.connection
rsCheckHardwareSoftwareForDups.CursorLocation = adUseClient
rsCheckHardwareSoftwareForDups.ActiveConnection = CurrentProject.connection
rst1.Open "Select * FROM lktblStandardSoftware"
rst2.Open "Select * FROM tblSoftware"
rsCheckHardwareSoftwareForDups.Open
rsCheckHardwareSoftwareForDups.Open strSQL
rst1.MoveFirst
If rsCheckHardwareSoftwareForDups.EOF Then
DoCmd.SetWarnings (False)
DoCmd.Hourglass (True)
While Not rst1.EOF
rst2.AddNew
strSQL = ""
strSQL = "INSERT INTO tblHardwareSoftware ( Software_ID, Tag) values ("
strSQL = strSQL & rst2.Fields("Software_Id" & ", " & [Forms]![frmmain]![txtTag] & ""
rst2.Fields("Software".Value = rst1.Fields("Standard_Software".Value
rst2.Fields("Version" = rst1.Fields("Version".Value
rst2.Update
DoCmd.RunSQL (strSQL)
Forms!frmsoftware.Requery
rst1.MoveNext
Wend
DoCmd.Hourglass (False)
Else
MsgBox ("This equipment already has the standard software updated.", vbOKOnly, "Software already updated."
Exit Sub
End If
Exit_Err_btnStandardSoftware_Click:
Exit Sub
Err_btnStandardSoftware_Click:
MsgBox Err.Description & Err.Number
Resume Err_btnStandardSoftware_Click:
SetWarnings = True
End Sub
Any help would be great.
Thanks
lb
This is the code that I have at this moment:
Private Sub btnStandardSoftware_Click()
Dim rst1 As ADODB.Recordset
Dim rst2 As ADODB.Recordset
Dim rsCheckHardwareSoftwareForDups As ADODB.Recordset
Dim strSQL As String
strSQL = "SELECT tblHardwareSoftware.Tag "
strSQL = strSQL & "FROM tblHardwareSoftware "
strSQL = strSQL & "WHERE (tblHardwareSoftware.Tag=[Forms]![frmmain]![txtTag]);"
On Error GoTo Err_btnStandardSoftware_Click
Set rst1 = New ADODB.Recordset
Set rst2 = New ADODB.Recordset
Set rsCheckHardwareSoftwareForDups = New ADODB.Recordset
rst1.ActiveConnection = CurrentProject.connection
rst2.ActiveConnection = CurrentProject.connection
rsCheckHardwareSoftwareForDups.CursorLocation = adUseClient
rsCheckHardwareSoftwareForDups.ActiveConnection = CurrentProject.connection
rst1.Open "Select * FROM lktblStandardSoftware"
rst2.Open "Select * FROM tblSoftware"
rsCheckHardwareSoftwareForDups.Open
rsCheckHardwareSoftwareForDups.Open strSQL
rst1.MoveFirst
If rsCheckHardwareSoftwareForDups.EOF Then
DoCmd.SetWarnings (False)
DoCmd.Hourglass (True)
While Not rst1.EOF
rst2.AddNew
strSQL = ""
strSQL = "INSERT INTO tblHardwareSoftware ( Software_ID, Tag) values ("
strSQL = strSQL & rst2.Fields("Software_Id" & ", " & [Forms]![frmmain]![txtTag] & ""
rst2.Fields("Software".Value = rst1.Fields("Standard_Software".Value
rst2.Fields("Version" = rst1.Fields("Version".Value
rst2.Update
DoCmd.RunSQL (strSQL)
Forms!frmsoftware.Requery
rst1.MoveNext
Wend
DoCmd.Hourglass (False)
Else
MsgBox ("This equipment already has the standard software updated.", vbOKOnly, "Software already updated."
Exit Sub
End If
Exit_Err_btnStandardSoftware_Click:
Exit Sub
Err_btnStandardSoftware_Click:
MsgBox Err.Description & Err.Number
Resume Err_btnStandardSoftware_Click:
SetWarnings = True
End Sub
Any help would be great.
Thanks
lb