tony007
Jun 23rd, 2005, 10:59 AM
Hi guys i a have bounded form that supposed to update/add and delete records from customers table. But it is acting very weried when i try to use it. For example in the pic below it shows my form trying to
add a new record number 8 .
http://i5.photobucket.com/albums/y180/method007/tryingtoaddrecord.jpg
After i added new record and if i press the button to bring me to first record i see my new record added to begining of list and if i press button to take me to last record which is number 8 it shows its customername value as blank! I be happy if some one help me fixt this strange problem. Also the first record in the db get delete with new record!
http://i5.photobucket.com/albums/y180/method007/beforeaddingrecords1.jpg ( value in table customer before adding new record)
http://i5.photobucket.com/albums/y180/method007/lastrecordshowsblank2.jpg
http://i5.photobucket.com/albums/y180/method007/afteraddingnewrecord3.jpg ( vlaus in table customer after adding new record .first record get deleted with out my intention!)
Now if i try to delete a record. should i number all the records or not ? I be happy if some one show me how to solve this problem as well.Thanks
http://i5.photobucket.com/albums/y180/method007/beforedeleting4.jpg ( values of customer table before deleting record)
http://i5.photobucket.com/albums/y180/method007/afterdeleting5.jpg
(values of customer table after deleting records)
my code
Option Compare Database
Private Sub cmdSearch_Click()
Dim strStudentRef As String
Dim strSearch As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtSearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Performs the search using value entered into txtSearch
'and evaluates this against values in customerno
DoCmd.ShowAllRecords
DoCmd.GoToControl ("customerno")
DoCmd.FindRecord Me!txtSearch
customerno.SetFocus
strStudentRef = customerno.Text
txtSearch.SetFocus
strSearch = txtSearch.Text
'If matching record found sets focus in customerno and shows msgbox
'and clears search control
If strStudentRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
customerno.SetFocus
txtSearch = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
End If
End Sub
Private Sub Command14_Click()
'''On Error GoTo Err_CmdAdd_Click
'''Me.DataEntry = True
'''Me.CmdFilter.Visible = False
'''Me.CmdShowAll.Visible = True
'''DoCmd.GoToRecord , , acNewRec
If DCount("*", "Customer") = 0 Then
Me.customerno = 1
Else
Me.customerno = DMax("Customerno", "Customer") + 1
Me.customerName.Value = " "
End If
'''Exit_CmdAdd_Click:
'''Exit Sub
'''Err_CmdAdd_Click:
'''MsgBox Err.Description
'''Resume Exit_CmdAdd_Click
End Sub
Private Sub cmdDelete_Click()
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End Sub
'''Private Sub cmdDelete_Click()
'''Dim x As Variant
'''x = MsgBox(" You are abut to delete " & Me.customerName & " from this table - proceed ? ", vbOKCancel)
'''If x = 1 Then
'''With myRS
'''.Delete
'''.MoveFirst
'''End With
'''End If
'''End Sub
add a new record number 8 .
http://i5.photobucket.com/albums/y180/method007/tryingtoaddrecord.jpg
After i added new record and if i press the button to bring me to first record i see my new record added to begining of list and if i press button to take me to last record which is number 8 it shows its customername value as blank! I be happy if some one help me fixt this strange problem. Also the first record in the db get delete with new record!
http://i5.photobucket.com/albums/y180/method007/beforeaddingrecords1.jpg ( value in table customer before adding new record)
http://i5.photobucket.com/albums/y180/method007/lastrecordshowsblank2.jpg
http://i5.photobucket.com/albums/y180/method007/afteraddingnewrecord3.jpg ( vlaus in table customer after adding new record .first record get deleted with out my intention!)
Now if i try to delete a record. should i number all the records or not ? I be happy if some one show me how to solve this problem as well.Thanks
http://i5.photobucket.com/albums/y180/method007/beforedeleting4.jpg ( values of customer table before deleting record)
http://i5.photobucket.com/albums/y180/method007/afterdeleting5.jpg
(values of customer table after deleting records)
my code
Option Compare Database
Private Sub cmdSearch_Click()
Dim strStudentRef As String
Dim strSearch As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtSearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Performs the search using value entered into txtSearch
'and evaluates this against values in customerno
DoCmd.ShowAllRecords
DoCmd.GoToControl ("customerno")
DoCmd.FindRecord Me!txtSearch
customerno.SetFocus
strStudentRef = customerno.Text
txtSearch.SetFocus
strSearch = txtSearch.Text
'If matching record found sets focus in customerno and shows msgbox
'and clears search control
If strStudentRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
customerno.SetFocus
txtSearch = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
End If
End Sub
Private Sub Command14_Click()
'''On Error GoTo Err_CmdAdd_Click
'''Me.DataEntry = True
'''Me.CmdFilter.Visible = False
'''Me.CmdShowAll.Visible = True
'''DoCmd.GoToRecord , , acNewRec
If DCount("*", "Customer") = 0 Then
Me.customerno = 1
Else
Me.customerno = DMax("Customerno", "Customer") + 1
Me.customerName.Value = " "
End If
'''Exit_CmdAdd_Click:
'''Exit Sub
'''Err_CmdAdd_Click:
'''MsgBox Err.Description
'''Resume Exit_CmdAdd_Click
End Sub
Private Sub cmdDelete_Click()
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End Sub
'''Private Sub cmdDelete_Click()
'''Dim x As Variant
'''x = MsgBox(" You are abut to delete " & Me.customerName & " from this table - proceed ? ", vbOKCancel)
'''If x = 1 Then
'''With myRS
'''.Delete
'''.MoveFirst
'''End With
'''End If
'''End Sub