Hello All,
I am hoping to get some help from anyone with more expertise, I have a form to edit a record in a table,
I have most of the script done but I am having a little trouble with my strSQL statement.
Code:
Set MyDB = CurrentDb
strSQL = "Select * From dbo_tbl_List_SiteVisit2 WHERE [IETM_ID] = " & Me!lboAVUMTaskMappingUpdate
I would like to have the Select statement to check for more than one column in the table. These columns [IETM_ID], [Maint_Funct],[MOS_ID],[Quantity],[Time] are what I would like to check and then
The same goes with the check for the records in the database, I would like to add columns to my check. If records exist then edit the record with information, if the record doesn't exist then create the record
Code:
'See if the Data has already been Captured, if not, Add, not Edit the Record
If DCount("*", "tbl_List_SiteVisit2", "[IETM_ID] = " & Me![lboAVUMTaskMappingUpdate]) = 0 Then
Here is the whole script, I poached it from another user and tried to modify it
but my learning curve keeps getting in the way.
Code:
Private Sub btnAVUMTMUDelete_Click()
Dim MyDB As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Set MyDB = CurrentDb
strSQL = "Select * From dbo_tbl_List_SiteVisit2 WHERE [IETM_ID] = " & Me!lboAVUMTaskMappingUpdate
'See if the Data has already been Captured, if not, Add, not Edit the Record
If DCount("*", "tbl_List_SiteVisit2", "[IETM_ID] = " & Me![lboAVUMTaskMappingUpdate]) = 0 Then
'NOT Captured/ADD
Set rst = MyDB.OpenRecordset("dbo_tbl_List_SiteVisit2", dbOpenDynaset, dbSeeChanges)
With rst
.AddNew
!IETM_ID = ctl
!Maint_Funct = Forms!frm_AVUM_TaskMapping_UpDate!cboTMMFo1
!MOS_ID = Forms!frm_AVUM_TaskMapping_UpDate!cboTMMOSo1
!Quantity = Forms!frm_AVUM_TaskMapping_UpDate!txboTMQtyo1
!Time = Forms!frm_AVUM_TaskMapping_UpDate!txboTMTimeo1
.Update
.Bookmark = .LastModified
End With
'Data Captured, so Edit the Recordset
Else
Set rst = MyDB.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
With rst
.Edit
!IETM_ID = ctl
!Maint_Funct = Forms!frm_AVUM_TaskMapping_UpDate!cboTMMFo1
!MOS_ID = Forms!frm_AVUM_TaskMapping_UpDate!cboTMMOSo1
!Quantity = Forms!frm_AVUM_TaskMapping_UpDate!txboTMQtyo1
!Time = Forms!frm_AVUM_TaskMapping_UpDate!txboTMTimeo1
.Update
End With
End If
rst.Close
strSQL = Nothing
Set rst = Nothing
End Sub
Any help would be much appreciated thanks