Hai
I have a Program with excel vba i would like to convert to access is it possible
Thanks
Shabee
Code
I have a Program with excel vba i would like to convert to access is it possible
Thanks
Shabee
Code
Code:
Option Explicit
Dim blnNew As Boolean
Dim TRows, i As Long
Private Sub cmdClose_Click()
If cmdClose.Caption = "Close" Then
Unload Me
Else
cmdClose.Caption = "Close"
cmdNew.Enabled = True
cmdDelete.Enabled = True
End If
End Sub
Private Sub cmdDelete_Click()
TRows = Worksheets("Data").Range("A1").CurrentRegion.Rows.Count
Dim strDel
strDel = MsgBox("Delete ?", vbYesNo, "Delete")
If strDel = vbYes Then
For i = 1 To TRows
If Trim(Worksheets("Data").Cells(i, 1).Value) = Trim(txtCollectionNo.Text) Then
' Sheet1.Range(i & ":" & i).Delete
Worksheets("Data").Range(i & ":" & i).Delete
txtCollectionNo.Text = ""
txtCustomerName.Text = ""
txtContact.Text = ""
txtIMEI.Text = ""
txtPhonemodel.Text = ""
txtProblem.Text = ""
txtCondition.Text = ""
txtCost.Text = ""
CheckBox1.Value = 0
CheckBox2.Value = 0
CheckBox3.Value = 0
txtStatus.Text = ""
txtSPRUsed.Text = ""
txtCharge.Text = ""
txtDate.Text = ""
Call prComboBoxFill
Exit For
End If
Next i
If Trim(ComboBox1.Text) = "" Then
cmdSave.Enabled = False
cmdDelete.Enabled = False
Else
cmdSave.Enabled = True
cmdDelete.Enabled = True
End If
cmdNew.Enabled = True
cmdClose.Caption = "Close"
End If
If Trim(txtCollectionNo.Text) = "" Then
cmdSave.Enabled = False
cmdDelete.Enabled = False
Frame2.Enabled = False
Else
cmdSave.Enabled = True
cmdDelete.Enabled = True
Frame2.Enabled = True
End If
End Sub
Private Sub cmdNew_Click()
blnNew = True
txtCollectionNo.Text = ""
txtCustomerName.Text = ""
txtContact.Text = ""
txtIMEI.Text = ""
txtPhonemodel.Text = ""
txtProblem.Text = ""
txtCondition.Text = ""
txtCost.Text = ""
txtDate.Text = Format(Now(), "dd-MMM-yyyy")
cmdClose.Caption = "Cancel"
cmdNew.Enabled = False
cmdDelete.Enabled = False
cmdSave.Enabled = True
Frame2.Enabled = True
End Sub
Private Sub cmdSave_Click()
If Trim(txtCollectionNo.Text) = "" Then
MsgBox "Enter CollectionNo.", vbCritical, "Save"
txtCollectionNo.SetFocus
Exit Sub
End If
Call prSave
cmdClose.Caption = "Close"
cmdNew.Enabled = True
ThisWorkbook.Save
End Sub
Private Sub prSave()
''''' Save the Data
If blnNew = True Then
TRows = Worksheets("Data").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Data").Range("A1")
.Offset(TRows, 0).Value = txtCollectionNo.Text
.Offset(TRows, 1).Value = txtCustomerName.Text
.Offset(TRows, 2).Value = txtContact.Text
.Offset(TRows, 3).Value = txtIMEI.Text
.Offset(TRows, 4).Value = txtPhonemodel.Text
.Offset(TRows, 5).Value = txtProblem.Text
.Offset(TRows, 6).Value = txtCondition.Text
.Offset(TRows, 7).Value = txtCost.Text
If CheckBox1.Value = True Then '''' Battery
.Offset(TRows, 8).Value = "Yes"
Else
.Offset(TRows, 8).Value = "No"
End If
If CheckBox2.Value = True Then '''' Sim
.Offset(TRows, 9).Value = "Yes"
Else
.Offset(TRows, 9).Value = "No"
End If
If CheckBox3.Value = True Then '''' MMC
.Offset(TRows, 10).Value = "Yes"
Else
.Offset(TRows, 10).Value = "No"
End If
.Offset(TRows, 11).Value = txtStatus.Text
.Offset(TRows, 12).Value = txtSPRUsed.Text
.Offset(TRows, 13).Value = txtCharge.Text
.Offset(TRows, 14).Value = txtDate.Text
MsgBox "Data Saved", vbInformation, "Save"
End With
txtCollectionNo.Text = ""
txtCustomerName.Text = ""
txtContact.Text = ""
txtIMEI.Text = ""
txtPhonemodel.Text = ""
txtProblem.Text = ""
txtCondition.Text = ""
txtCost.Text = ""
CheckBox1.Value = 0
CheckBox2.Value = 0
CheckBox3.Value = 0
txtStatus.Text = ""
txtSPRUsed.Text = ""
txtCharge.Text = ""
txtDate.Text = ""
Call prComboBoxFill
Else
For i = 2 To TRows
If Trim(Worksheets("Data").Cells(i, 1).Value) = Trim(txtCollectionNo.Text) Then
Worksheets("Data").Cells(i, 1).Value = txtCollectionNo.Text
Worksheets("Data").Cells(i, 2).Value = txtCustomerName.Text
Worksheets("Data").Cells(i, 3).Value = txtContact.Text
Worksheets("Data").Cells(i, 4).Value = txtIMEI.Text
Worksheets("Data").Cells(i, 5).Value = txtPhonemodel.Text
Worksheets("Data").Cells(i, 6).Value = txtProblem.Text
Worksheets("Data").Cells(i, 7).Value = txtCondition.Text
Worksheets("Data").Cells(i, 8).Value = txtCost.Text
If CheckBox1.Value = True Then '''' Battery
Worksheets("Data").Cells(i, 9).Value = "Yes"
Else
Worksheets("Data").Cells(i, 9).Value = "No"
End If
If CheckBox2.Value = True Then '''' Sim
Worksheets("Data").Cells(i, 10).Value = "Yes"
Else
Worksheets("Data").Cells(i, 10).Value = "No"
End If
If CheckBox3.Value = True Then '''' MMC
Worksheets("Data").Cells(i, 11).Value = "Yes"
Else
Worksheets("Data").Cells(i, 11).Value = "No"
End If
Worksheets("Data").Cells(i, 12).Value = txtStatus.Text
Worksheets("Data").Cells(i, 13).Value = txtSPRUsed.Text
Worksheets("Data").Cells(i, 14).Value = txtCharge.Text
Worksheets("Data").Cells(i, 15).Value = txtDate.Text
MsgBox "Data Saved", vbInformation, "Save"
txtCollectionNo.Text = ""
txtCustomerName.Text = ""
txtContact.Text = ""
txtIMEI.Text = ""
txtPhonemodel.Text = ""
txtProblem.Text = ""
txtCondition.Text = ""
txtCost.Text = ""
CheckBox1.Value = 0
CheckBox2.Value = 0
CheckBox3.Value = 0
txtStatus.Text = ""
txtSPRUsed.Text = ""
txtCharge.Text = ""
txtDate.Text = ""
Exit For
End If
Next i
End If
blnNew = False
If Trim(txtCollectionNo.Text) = "" Then
cmdSave.Enabled = False
cmdDelete.Enabled = False
Frame2.Enabled = False
Else
cmdSave.Enabled = True
cmdDelete.Enabled = True
Frame2.Enabled = True
End If
End Sub
Private Sub cmdSearch_Click()
Dim strText() As String
blnNew = False
txtCollectionNo.Text = ""
txtCustomerName.Text = ""
txtContact.Text = ""
txtIMEI.Text = ""
txtPhonemodel.Text = ""
txtProblem.Text = ""
txtCondition.Text = ""
txtCost.Text = ""
strText = Split(ComboBox1.Text, vbTab)
TRows = Worksheets("Data").Range("A1").CurrentRegion.Rows.Count
For i = 2 To TRows
If Trim(Worksheets("Data").Cells(i, 1).Value) = Trim(strText(0)) Then
txtCollectionNo.Text = Worksheets("Data").Cells(i, 1).Value
txtCustomerName.Text = Worksheets("Data").Cells(i, 2).Value
txtContact.Text = Worksheets("Data").Cells(i, 3).Value
txtIMEI.Text = Worksheets("Data").Cells(i, 4).Value
txtPhonemodel.Text = Worksheets("Data").Cells(i, 5).Value
txtProblem.Text = Worksheets("Data").Cells(i, 6).Value
txtCondition.Text = Worksheets("Data").Cells(i, 7).Value
txtCost.Text = Worksheets("Data").Cells(i, 8).Value
If Trim(Worksheets("Data").Cells(i, 9).Value) = "Yes" Then
CheckBox1.Value = 1
Else
CheckBox1.Value = 0
End If
If Trim(Worksheets("Data").Cells(i, 10).Value) = "Yes" Then
CheckBox2.Value = 1
Else
CheckBox2.Value = 0
End If
If Trim(Worksheets("Data").Cells(i, 11).Value) = "Yes" Then
CheckBox3.Value = 1
Else
CheckBox3.Value = 0
End If
txtStatus.Text = Worksheets("Data").Cells(i, 12).Value
txtSPRUsed.Text = Worksheets("Data").Cells(i, 13).Value
txtCharge.Text = Worksheets("Data").Cells(i, 14).Value
txtDate.Text = Format(Worksheets("Data").Cells(i, 15).Value, "dd-MMM-yyyy")
Exit For
End If
Next i
If Trim(txtCollectionNo.Text) = "" Then
cmdSave.Enabled = False
cmdDelete.Enabled = False
Frame2.Enabled = False
Else
cmdSave.Enabled = True
cmdDelete.Enabled = True
Frame2.Enabled = True
End If
End Sub
Private Sub prComboBoxFill()
TRows = Worksheets("Data").Range("A1").CurrentRegion.Rows.Count
ComboBox1.Clear
For i = 2 To TRows
ComboBox1.AddItem Worksheets("Data").Cells(i, 1).Value & vbTab & Worksheets("Data").Cells(i, 2).Value
Next i
End Sub
Private Sub txtDate_AfterUpdate()
If IsDate(txtDate.Text) = False Then
MsgBox "Invalid Date", vbCritical, "Emp Details"
txtDate.SetFocus
End If
End Sub
Private Sub txtDate_Change()
End Sub
Private Sub txtDate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If IsDate(txtDate.Text) = False Then
MsgBox "Invalid Date", vbCritical, "Emp Details"
txtDate.SetFocus
End If
End Sub
Private Sub UserForm_Initialize()
Call RemoveCaption(Me)
Application.Visible = False
Call prComboBoxFill
cmdSave.Enabled = False
cmdDelete.Enabled = False
Frame2.Enabled = False
End Sub
'
'~~> Rest of the code
'
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
ThisWorkbook.Close SaveChanges:=True '<~~ Save workbook before closing
DoEvents
Application.Visible = True
End Sub
Last edited by a moderator: