Hi
I have successfully created the code below using an online tutorial. I have two forms whic are transferring to 2 different databases. The first form has worked no problem. I copied the code below to create the second transfer of data and added the number '1' to differentiate the two. It is not working. Please could you help me as where I have gone wrong. i have highlighted in Bold where i added 1. The reset seems to work ok.
thanks
Sub transfer()
Dim objList As ListObject ' to store or refer the table name CovidTestData
Dim shForm As Worksheet ' it will refer to the Worksheet 'Form"
Set objList = ThisWorkbook.Sheets("ResultDatabase").ListObjects("ResultData")
Set shForm = ThisWorkbook.Sheets("Result")
If objList.DataBodyRange(1, 1).Value <> "" Then
objList.ListRows.Add Position:=1
End If
With objList
.DataBodyRange(1, 1).Value = shForm.Range("G8").Value
.DataBodyRange(1, 2).Value = shForm.Range("G10").Value
.DataBodyRange(1, 3).Value = shForm.Range("G12").Value
.DataBodyRange(1, 4).Value = Application.UserName
End With
shForm.Range("G8,G10,G12").Value = ""
ThisWorkbook.Save
End Sub
Sub TransferToTable1()
Dim imessage As VbMsgBoxResult
imessage = MsgBox("Do you want to transfer this information to the Database?", vbYesNo + vbQuestion, "Confirmation")
If imessage = vbNo Then Exit Sub
Call transfer1
End Sub
Sub Reset1()
Dim imessage As VbMsgBoxResult
imessage = MsgBox("Do you want to reset the form?", vbYesNo + vbQuestion, "Confirmation")
If imessage = vbNo Then Exit Sub
Sheets("Result").Range("G8,G10").Value = ""
Sheets("Result").Range("G12").Value = "=now()"
End Sub
I have successfully created the code below using an online tutorial. I have two forms whic are transferring to 2 different databases. The first form has worked no problem. I copied the code below to create the second transfer of data and added the number '1' to differentiate the two. It is not working. Please could you help me as where I have gone wrong. i have highlighted in Bold where i added 1. The reset seems to work ok.
thanks
Sub transfer()
Dim objList As ListObject ' to store or refer the table name CovidTestData
Dim shForm As Worksheet ' it will refer to the Worksheet 'Form"
Set objList = ThisWorkbook.Sheets("ResultDatabase").ListObjects("ResultData")
Set shForm = ThisWorkbook.Sheets("Result")
If objList.DataBodyRange(1, 1).Value <> "" Then
objList.ListRows.Add Position:=1
End If
With objList
.DataBodyRange(1, 1).Value = shForm.Range("G8").Value
.DataBodyRange(1, 2).Value = shForm.Range("G10").Value
.DataBodyRange(1, 3).Value = shForm.Range("G12").Value
.DataBodyRange(1, 4).Value = Application.UserName
End With
shForm.Range("G8,G10,G12").Value = ""
ThisWorkbook.Save
End Sub
Sub TransferToTable1()
Dim imessage As VbMsgBoxResult
imessage = MsgBox("Do you want to transfer this information to the Database?", vbYesNo + vbQuestion, "Confirmation")
If imessage = vbNo Then Exit Sub
Call transfer1
End Sub
Sub Reset1()
Dim imessage As VbMsgBoxResult
imessage = MsgBox("Do you want to reset the form?", vbYesNo + vbQuestion, "Confirmation")
If imessage = vbNo Then Exit Sub
Sheets("Result").Range("G8,G10").Value = ""
Sheets("Result").Range("G12").Value = "=now()"
End Sub