
April 24th, 2012, 02:02 AM
|
|
Registered User
|
|
Join Date: Apr 2012
Posts: 1
Time spent in forums: 22 m 37 sec
Reputation Power: 0
|
|
|
In Excel form next or previous cmd button doesn't work
hi all
I am new in dev shed. iam working on excel form which is use to data entry but there is littile mistake. in my excel form next or previous cmd button doesn't show data from sheet to form here is code :-
Private Sub cmdNext_Click()
If ActiveCell.Column = Columns.Count Then
MsgBox "There is no next cell"
Exit Sub
End If
ActiveCell.Offset(0, 1).Select
End Sub
Private Sub cmdpre_Click()
If ActiveCell.Column = 1 Then
MsgBox "There is no previous cell"
Exit Sub
End If
ActiveCell.Offset(0, -1).Select
End Sub
Private Sub cmdsave_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("sheet1")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a student number
If Trim(Me.txtsrnu.Value) = "" Then
Me.txtsrnu.SetFocus
MsgBox "PLEASE ENTER A SERIAL NUMBER !!!"
Exit Sub
End If
If Trim(Me.txtname.Value) = "" Then
Me.txtname.SetFocus
MsgBox "PLEASE ENTER A NAME !!!"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtsrnu.Value
ws.Cells(iRow, 2).Value = Me.txtname.Value
ws.Cells(iRow, 3).Value = Me.txtfname.Value
ws.Cells(iRow, 4).Value = Me.txtdob.Value
ws.Cells(iRow, 5).Value = Me.txtadd.Value
ws.Cells(iRow, 6).Value = Me.txtgender.Value
ws.Cells(iRow, 7).Value = Me.txtcat.Value
ws.Cells(iRow, 8).Value = Me.txtquali.Value
ws.Cells(iRow, 9).Value = Me.txtper.Value
ws.Cells(iRow, 10).Value = Me.txtafnu.Value
ws.Cells(iRow, 11).Value = Me.txtnu.Value
ws.Cells(iRow, 12).Value = Me.txtenrnu.Value
'clear the data
Me.txtsrnu.Value = ""
Me.txtname.Value = ""
Me.txtfname.Value = ""
Me.txtdob.Value = ""
Me.txtadd.Value = ""
Me.txtgender.Value = ""
Me.txtcat.Value = ""
Me.txtquali.Value = ""
Me.txtper.Value = ""
Me.txtafnu.Value = ""
Me.txtnu.Value = ""
Me.txtenrnu.Value = ""
MsgBox "RECORD SAVED SUCCESSFULLY!!!"
Me.txtsrnu.SetFocus
End Sub
Private Sub txtadd_Change()
On Error Resume Next
txtadd = UCase(txtadd)
On Error GoTo 0
End Sub
Private Sub txtafnu_Change()
On Error Resume Next
txtafnu = UCase(txtafnu)
On Error GoTo 0
End Sub
Private Sub txtcat_Change()
On Error Resume Next
txtcat = UCase(txtcat)
On Error GoTo 0
End Sub
Private Sub txtdob_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Me.txtdob.Value = Format(Me.txtdob.Value, "dd/mm/YYYY")
End Sub
Private Sub txtenrnu_Change()
On Error Resume Next
txtenrnu = UCase(txtenrnu)
On Error GoTo 0
End Sub
Private Sub txtfname_Change()
On Error Resume Next
txtfname = UCase(txtfname)
On Error GoTo 0
End Sub
Private Sub txtgender_Change()
On Error Resume Next
txtgender = UCase(txtgender)
On Error GoTo 0
End Sub
Private Sub txtname_Change()
On Error Resume Next
txtname = UCase(txtname)
On Error GoTo 0
End Sub
Private Sub txtnu_Change()
OnlyNumbers
End Sub
Private Sub txtper_Change()
OnlyNumbers
End Sub
Private Sub txtsrnu_Change()
OnlyNumbers
End Sub
Private Sub OnlyNumbers()
If TypeName(Me.ActiveControl) = "TextBox" Then
With Me.ActiveControl
If Not IsNumeric(.Value) And .Value <> vbNullString Then
MsgBox "Sorry, only numbers allowed"
.Value = vbNullString
End If
End With
End If
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the close button!"
End If
End Sub
|