Hi there. I'm new in VBA. Please give me some guidance.
I facing this problem. Can anyone spot where the error are? Much appreciated.
Private Sub CommandButton7_Click()
Dim Answers As String
Dim Mynote As String
Dim Answer As String
Dim lRow As Long
Set ws = Worksheets("Rekod")
'Place your text here
Mynote = "Adakah anda telah klik butang 'Tambah Rekod'?"
'Display Message Box
Answers = MsgBox(Mynote, vbQuestion + vbYesNo, "Anda Pasti?")
If Answers = vbYes Then
Answer = MsgBox("Adakah anda ingin save file ini?", vbQuestion + vbYesNoCancel, "Save File?")
Select Case Answer
Case vbYes
'find the last row
lRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Row
'Copy data to the database
With ws
.Cells(lRow + 1, 1).Value = .Cells(lRow, 1).Value
.Cells(lRow + 1, 2).Value = .Cells(lRow, 2).Value
End With
'save the file
ThisWorkbook.Save
'code to proceed to next form
Unload Me
Rekod.Show
Exit Sub
Case vbNo 'not save the file
'find the last row
lRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Row
'Copy data to the database
With ws
.Cells(lRow + 1, 1).Value = .Cells(lRow, 1).Value
.Cells(lRow + 1, 2).Value = .Cells(lRow, 2).Value
'code to proceed to next form
Unload Me
Rekod.Show
Exit Sub
Case vbCancel
Unload Me
Rekod.Show
Exit Sub
End Select
Else
'code for click back butang Tambah rekod
Exit Sub
End If
End Sub
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.
----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA
----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com
----------------------------------
Tidak ada komentar:
Posting Komentar