473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Validating data entry (Access 2000)

I am trying to alert a user , by using a message box, to state the various missing data.This works OK except when all data is entered as appropriate I still get the "Warning Message" for missing data! The program therefore does not progress!

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command107_Click()
  2. Dim objPDF As New PDFClass
  3. Dim IngResult As Long
  4. Const PDFENGINE_PDF995 = 5
  5. Dim stFaxNo As String
  6. Dim rptFaxDeal As String
  7. Dim strBroker As String
  8. Dim strTable As String
  9. Dim strError As String
  10. Dim blnError As String
  11.  
  12. strBroker = Forms!frmMainForm.Text265
  13. strTable = "tblDeals" + strBroker
  14. blnError = False
  15.  
  16. strError = "Please complete the following:" & vbCrLf
  17.  
  18.             If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  19.                   blnError = True
  20.                       strError = strError & "Vehicle Details" & vbCrLf
  21.  
  22.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  23.                     blnError = True
  24.                         End If
  25.             If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Miles]) Then
  26.                   blnError = True
  27.                       strError = strError & "Mileage" & vbCrLf
  28.  
  29.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Miles]) Then
  30.                     blnError = True
  31.                         End If
  32.              If IsNull([Forms]![frmDeal]![frmDealsSub].Form![RegNo]) Then
  33.                   blnError = True
  34.                       strError = strError & "Registration Number" & vbCrLf
  35.  
  36.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![RegNo]) Then
  37.                     blnError = True
  38.                         End If
  39.             If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Year]) Then
  40.                   blnError = True
  41.                       strError = strError & "Year of Registration" & vbCrLf
  42.  
  43.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Year]) Then
  44.                     blnError = True
  45.                         End If
  46.               If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text118]) Then
  47.                   blnError = True
  48.                       strError = strError & "No. of Owners" & vbCrLf
  49.  
  50.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text118]) Then
  51.                     blnError = True
  52.                         End If
  53.               If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text180]) Then
  54.                   blnError = True
  55.                       strError = strError & "Service History" & vbCrLf
  56.  
  57.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text180]) Then
  58.                     blnError = True
  59.                         End If
  60.                  If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Import]) Then
  61.                   blnError = True
  62.                       strError = strError & "UK car or Import" & vbCrLf
  63.  
  64.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Import]) Then
  65.                     blnError = True
  66.                         End If
  67.                If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Colour]) Then
  68.                   blnError = True
  69.                       strError = strError & "Vehicle Colour" & vbCrLf
  70.  
  71.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Colour]) Then
  72.                     blnError = True
  73.                         End If
  74.                 If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Interior]) Then
  75.                   blnError = True
  76.                       strError = strError & "Interior" & vbCrLf
  77.  
  78.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Interior]) Then
  79.                     blnError = True
  80.                         End If
  81.  
  82.                  If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Damage]) Then
  83.                   blnError = True
  84.                       strError = strError & "Condition" & vbCrLf
  85.  
  86.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Damage]) Then
  87.                     blnError = True
  88.                         End If
  89.  
  90.                  If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text250]) Then
  91.                   blnError = True
  92.                       strError = strError & "Any Extras" & vbCrLf
  93.  
  94.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text250]) Then
  95.                     blnError = True
  96.                         End If
  97.  
  98.                  If IsNull([Forms]![frmDeal]![frmDealsSub].Form![DealBid]) Then
  99.                   blnError = True
  100.                       strError = strError & "Amount Bid" & vbCrLf
  101.  
  102.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![DealBid]) Then
  103.                     blnError = True
  104.                         End If
  105.  
  106.                     If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text148]) Then
  107.                   blnError = True
  108.                       strError = strError & "Sellers Comments" & vbCrLf
  109.  
  110.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text148]) Then
  111.                     blnError = True
  112.                         End If
  113.                  If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text152]) Then
  114.                   blnError = True
  115.                       strError = strError & "Sellers Collection details" & vbCrLf
  116.  
  117.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text152]) Then
  118.                     blnError = True
  119.                         End If
  120.  
  121.                     If IsNull([Forms]![frmDeal]![frmDealsSub].Form![AmountFaxed]) Then
  122.                   blnError = True
  123.                       strError = strError & "Selling Brokers Fee" & vbCrLf
  124.  
  125.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![AmountFaxed]) Then
  126.                     blnError = True
  127.                         End If
  128.  
  129.                    If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text150]) Then
  130.                   blnError = True
  131.                       strError = strError & "Buyers Comments" & vbCrLf
  132.  
  133.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text150]) Then
  134.                     blnError = True
  135.                         End If
  136.  
  137.                    If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text154]) Then
  138.                   blnError = True
  139.                       strError = strError & "Buyers Collection details" & vbCrLf
  140.  
  141.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text154]) Then
  142.                     blnError = True
  143.                         End If
  144.  
  145.                    If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text145]) Then
  146.                   blnError = True
  147.                       strError = strError & "Buying Brokers Fee" & vbCrLf
  148.  
  149.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text145]) Then
  150.                     blnError = True
  151.                         End If
  152.  
  153.            If blnError = True Then
  154.                 Cancel = True
  155.                     MsgBox strError, vbOKOnly + vbCritical, "Stop!"
  156.                          Exit Sub
  157.               End If
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165. MissingBuyer:
  166. Data1 = MsgBox("Buying Dealers details must be completed to continue", vbOKCancel, "Missing data!")
  167. If Data1 = vbCancel Then Exit Sub
  168. If Data1 = vbOK Then Me.Text36.SetFocus
  169. Me.Text36.BackColor = 8454143
  170. Exit Sub
  171.  
  172.  
  173. Continue:
  174. If IsNull(Me.Text36) Or IsNull(cboBuyingDealer) Or cboBuyingContact = "" Or Text188 = "" Or txtFaxNo = "" Then GoTo MissingBuyer Else
  175. stFaxNo = Me.DealNo
  176. rptFaxDeal = "rptFaxDealFax"
  177. ViewReport = "C:\PDF995\" & stFaxNo + ".pdf"
  178. SQLtext = "INSERT INTO " & strTable & " (BuyingDealer)SELECT Text97  WHERE FROM " & strTable & "(((" & strTable & ".Ticket)=[Forms]![frmDeal].[Text178]));"
  179. SQLtext1 = "UPDATE " & strTable & " SET " & strTable & ".BuyingDealer = [Forms]![frmDeal].[text97]WHERE (((" & strTable & ".Ticket)=[Forms]![frmDeal].[Text178]));"
  180.  
  181. DoCmd.RunSQL (SQLtext1)
  182. With objPDF
  183.     .PDFEngine = PDFENGINE_PDF995
  184.     .reportname = rptFaxDeal
  185.     .outputfile = "C:\PDF995\" & stFaxNo + ".pdf"
  186.     .PrintImage
  187.     IngResult = .Result
  188.  
  189.     End With
  190.  
  191.     Set objPDF = Nothing
  192.     DoCmd.OpenReport "rptFaxDealFaxSell", acPreview
  193.     Reports!rptFaxDealFaxSell.Caption = stFaxNo + "-S" + ".pdf"
  194.       DoCmd.OpenReport "rptFaxDealFaxBuy", acPreview
  195.     Reports!rptFaxDealFaxBuy.Caption = stFaxNo + "-B" + ".pdf"
  196.       Me.comSendFax.Enabled = True
  197.  
  198.  
  199. End Sub
  200.  
  201.  
As you will have spotted I have used script from other sources as I am not at a level to write my own - hence my inability to solve the problem.

Any help, or pointers, would be greatly appreciated.
Nov 2 '07 #1
13 1872
ADezii
8,834 Expert 8TB
boliches, I'm not speaking for the rest of the Moderators/Experts in this Forum, but personally I will not attempt to decipher 200 lines of code unles it is properly Formatted and Tagged. If you can get the code in a more readable and tagged format, I will be more than happy to have a look at it.
Nov 2 '07 #2
boliches, I'm not speaking for the rest of the Moderators/Experts in this Forum, but personally I will not attempt to decipher 200 lines of code unles it is properly Formatted and Tagged. If you can get the code in a more readable and tagged format, I will be more than happy to have a look at it.

I dont fully understand what you want, but I have cut it down to a manageable size (I hope)
Expand|Select|Wrap|Line Numbers
  1. blnError = False
  2.  
  3. strError = "Please complete the following:" & vbCrLf
  4.  
  5.             If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  6.                   blnError = True
  7.                       strError = strError & "Vehicle Details" & vbCrLf
  8.  
  9.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  10.                     blnError = True
  11.                         End If
  12.             If blnError = True Then
  13.                 Cancel = True
  14.                     MsgBox strError, vbOKOnly + vbCritical, "Stop!"
  15.                          Exit Sub
  16.               End If
  17.  
The problem is the MsgBox is still shown even when all relevant Text Boxes are filled
Nov 3 '07 #3
ADezii
8,834 Expert 8TB
I dont fully understand what you want, but I have cut it down to a manageable size (I hope)
Expand|Select|Wrap|Line Numbers
  1. blnError = False
  2.  
  3. strError = "Please complete the following:" & vbCrLf
  4.  
  5.             If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  6.                   blnError = True
  7.                       strError = strError & "Vehicle Details" & vbCrLf
  8.  
  9.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  10.                     blnError = True
  11.                         End If
  12.             If blnError = True Then
  13.                 Cancel = True
  14.                     MsgBox strError, vbOKOnly + vbCritical, "Stop!"
  15.                          Exit Sub
  16.               End If
  17.  
The problem is the MsgBox is still shown even when all relevant Text Boxes are filled
This is what I was referring to, I'll look at it as soon as I get a chance.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command107_Click()
  2. Dim objPDF As New PDFClass
  3. Dim IngResult As Long
  4. Const PDFENGINE_PDF995 = 5
  5. Dim stFaxNo As String
  6. Dim rptFaxDeal As String
  7. Dim strBroker As String
  8. Dim strTable As String
  9. Dim strError As String
  10. Dim blnError As String
  11.  
  12. strBroker = Forms!frmMainForm.Text265
  13. strTable = "tblDeals" + strBroker
  14. blnError = False
  15.  
  16. strError = "Please complete the following:" & vbCrLf
  17.  
  18. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  19.   blnError = True
  20.   trError = strError & "Vehicle Details" & vbCrLf
  21. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  22.   blnError = True
  23. End If
  24.  
  25. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Miles]) Then
  26.   blnError = True
  27.   strError = strError & "Mileage" & vbCrLf
  28. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Miles]) Then
  29.   blnError = True
  30. End If
  31.  
  32. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![RegNo]) Then
  33.   blnError = True
  34.   strError = strError & "Registration Number" & vbCrLf
  35. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![RegNo]) Then
  36.   blnError = True
  37. End If
  38.  
  39. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Year]) Then
  40.   blnError = True
  41.   strError = strError & "Year of Registration" & vbCrLf
  42. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Year]) Then
  43.   blnError = True
  44. End If
  45.  
  46. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text118]) Then
  47.   blnError = True
  48.   strError = strError & "No. of Owners" & vbCrLf
  49. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text118]) Then
  50.   blnError = True
  51. End If
  52.  
  53. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text180]) Then
  54.   blnError = True
  55.   strError = strError & "Service History" & vbCrLf
  56. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text180]) Then
  57.   blnError = True
  58. End If
  59.  
  60. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Import]) Then
  61.   blnError = True
  62.   strError = strError & "UK car or Import" & vbCrLf
  63. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Import]) Then
  64.   blnError = True
  65. End If
  66.  
  67. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Colour]) Then
  68.   blnError = True
  69.   strError = strError & "Vehicle Colour" & vbCrLf
  70. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Colour]) Then
  71.   blnError = True
  72. End If
  73.  
  74. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Interior]) Then
  75.   blnError = True
  76.   strError = strError & "Interior" & vbCrLf
  77. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Interior]) Then
  78.   blnError = True
  79. End If
  80.  
  81. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Damage]) Then
  82.   blnError = True
  83.   strError = strError & "Condition" & vbCrLf
  84. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Damage]) Then
  85.   blnError = True
  86. End If
  87.  
  88. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text250]) Then
  89.   blnError = True
  90.   strError = strError & "Any Extras" & vbCrLf
  91. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text250]) Then
  92.   blnError = True
  93. End If
  94.  
  95. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![DealBid]) Then
  96.   blnError = True
  97.   strError = strError & "Amount Bid" & vbCrLf
  98. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![DealBid]) Then
  99.   blnError = True
  100. End If
  101.  
  102. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text148]) Then
  103.   blnError = True
  104.   strError = strError & "Sellers Comments" & vbCrLf
  105. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text148]) Then
  106.   blnError = True
  107. End If
  108.  
  109. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text152]) Then
  110.   blnError = True
  111.   strError = strError & "Sellers Collection details" & vbCrLf
  112. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text152]) Then
  113.   blnError = True
  114. End If
  115.  
  116. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![AmountFaxed]) Then
  117.   blnError = True
  118.   strError = strError & "Selling Brokers Fee" & vbCrLf
  119. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![AmountFaxed]) Then
  120.   blnError = True
  121. End If
  122.  
  123. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text150]) Then
  124.   blnError = True
  125.   strError = strError & "Buyers Comments" & vbCrLf
  126. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text150]) Then
  127.   blnError = True
  128. End If
  129.  
  130. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text154]) Then
  131.   blnError = True
  132.   strError = strError & "Buyers Collection details" & vbCrLf
  133. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text154]) Then
  134.   blnError = True
  135. End If
  136.  
  137. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text145]) Then
  138.   blnError = True
  139.   strError = strError & "Buying Brokers Fee" & vbCrLf
  140. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text145]) Then
  141.   blnError = True
  142. End If
  143.  
  144. If blnError = True Then
  145.   Cancel = True
  146.   MsgBox strError, vbOKOnly + vbCritical, "Stop!"
  147.     Exit Sub
  148. End If
  149.  
  150. MissingBuyer:
  151. Data1 = MsgBox("Buying Dealers details must be completed to continue", vbOKCancel, "Missing data!")
  152. If Data1 = vbCancel Then Exit Sub
  153. If Data1 = vbOK Then Me.Text36.SetFocus
  154.   Me.Text36.BackColor = 8454143
  155.     Exit Sub
  156.  
  157.  
  158. Continue:
  159. If IsNull(Me.Text36) Or IsNull(cboBuyingDealer) Or cboBuyingContact = "" Or Text188 = "" Or txtFaxNo = "" Then
  160.   GoTo MissingBuyer
  161. Else
  162.   stFaxNo = Me.DealNo
  163.   rptFaxDeal = "rptFaxDealFax"
  164.   ViewReport = "C:\PDF995\" & stFaxNo + ".pdf"
  165.   SQLtext = "INSERT INTO " & strTable & " (BuyingDealer)SELECT Text97  WHERE FROM " & strTable & "(((" & strTable & ".Ticket)=[Forms]![frmDeal].[Text178]));"
  166.   SQLtext1 = "UPDATE " & strTable & " SET " & strTable & ".BuyingDealer = [Forms]![frmDeal].[text97]WHERE (((" & strTable & ".Ticket)=[Forms]![frmDeal].[Text178]));"
  167.  
  168.   DoCmd.RunSQL (SQLtext1)
  169.  
  170. With objPDF
  171.   .PDFEngine = PDFENGINE_PDF995
  172.   .reportname = rptFaxDeal
  173.   .outputfile = "C:\PDF995\" & stFaxNo + ".pdf"
  174.   .PrintImage
  175.     IngResult = .Result
  176. End With
  177.  
  178. Set objPDF = Nothing
  179.  
  180. DoCmd.OpenReport "rptFaxDealFaxSell", acPreview
  181. Reports!rptFaxDealFaxSell.Caption = stFaxNo + "-S" + ".pdf"
  182. DoCmd.OpenReport "rptFaxDealFaxBuy", acPreview
  183. Reports!rptFaxDealFaxBuy.Caption = stFaxNo + "-B" + ".pdf"
  184.   Me.comSendFax.Enabled = True
  185. End Sub
NOTE: Is there any reason why the Validation is not done in the BeforeUpdate() Event of frmDeal?
Nov 3 '07 #4
ADezii
8,834 Expert 8TB
I dont fully understand what you want, but I have cut it down to a manageable size (I hope)
Expand|Select|Wrap|Line Numbers
  1. blnError = False
  2.  
  3. strError = "Please complete the following:" & vbCrLf
  4.  
  5.             If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  6.                   blnError = True
  7.                       strError = strError & "Vehicle Details" & vbCrLf
  8.  
  9.               ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  10.                     blnError = True
  11.                         End If
  12.             If blnError = True Then
  13.                 Cancel = True
  14.                     MsgBox strError, vbOKOnly + vbCritical, "Stop!"
  15.                          Exit Sub
  16.               End If
  17.  
The problem is the MsgBox is still shown even when all relevant Text Boxes are filled
It appears that with your current logic, blnError will never evaluate to False. In the If...End If Statements, it seems to me that the ElseIf Clauses (Not IsNull()) should set the value of blnError to False, and the code syntax can be shortened. A couple of examples will illlustrate my point:
Expand|Select|Wrap|Line Numbers
  1. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  2.   blnError = True
  3.   trError = strError & "Vehicle Details" & vbCrLf
  4. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  5.   blnError = True
  6. End If
  7.  
  8. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Miles]) Then
  9.   blnError = True
  10.   strError = strError & "Mileage" & vbCrLf
  11. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Miles]) Then
  12.   blnError = True
  13. End If
try
Expand|Select|Wrap|Line Numbers
  1. 'It's either Not Null or Null
  2. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  3.   blnError = True
  4.   trError = strError & "Vehicle Details" & vbCrLf
  5. Else
  6.   blnError = False
  7. End If
  8.  
  9. 'It's either Not Null or Null           
  10. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Miles]) Then
  11.   blnError = True
  12.   strError = strError & "Mileage" & vbCrLf
  13. Else
  14.   blnError = False
  15. End If
  16.  
Nov 3 '07 #5
It appears that with your current logic, blnError will never evaluate to False. In the If...End If Statements, it seems to me that the ElseIf Clauses (Not IsNull()) should set the value of blnError to False, and the code syntax can be shortened. A couple of examples will illlustrate my point:
Expand|Select|Wrap|Line Numbers
  1. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  2.   blnError = True
  3.   trError = strError & "Vehicle Details" & vbCrLf
  4. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  5.   blnError = True
  6. End If
  7.  
  8. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Miles]) Then
  9.   blnError = True
  10.   strError = strError & "Mileage" & vbCrLf
  11. ElseIf Not IsNull([Forms]![frmDeal]![frmDealsSub].Form![Miles]) Then
  12.   blnError = True
  13. End If
try
Expand|Select|Wrap|Line Numbers
  1. 'It's either Not Null or Null
  2. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  3.   blnError = True
  4.   trError = strError & "Vehicle Details" & vbCrLf
  5. Else
  6.   blnError = False
  7. End If
  8.  
  9. 'It's either Not Null or Null           
  10. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Miles]) Then
  11.   blnError = True
  12.   strError = strError & "Mileage" & vbCrLf
  13. Else
  14.   blnError = False
  15. End If
  16.  

Have tried your suggestion, but for some reason when a textbox is null "blnError" still shows "blnError = False" and not "blnError = True"! WHY?? Is it because at the very beginning of the code I have

Expand|Select|Wrap|Line Numbers
  1. Dim blnError As String
  2. blnError = False
  3.  
I have concluded the script with:

Expand|Select|Wrap|Line Numbers
  1.  If blnError = True Then
  2.                 Cancel = True
  3.                     MsgBox strError, vbOKOnly + vbCritical, "Stop!"
  4.                          Exit Sub
  5.            Else: GoTo Continue 
  6.  End If
  7.  
  8.  
Would this be right? As I get the feeling this code is not as you guys would write it! ("Continue:" is where the concluding code is to complete the task)

Your help please as I am struggling with getting blnError to equal the correct action ie False when False and True when True.
Nov 4 '07 #6
I meant to ask how you "Formatted and Tagged" the script to make it easier to read, also what is the benefit of putting the script in the "Before Update" event procedure as against on a Command Button? Is it a speed related thing?
Nov 4 '07 #7
ADezii
8,834 Expert 8TB
I meant to ask how you "Formatted and Tagged" the script to make it easier to read, also what is the benefit of putting the script in the "Before Update" event procedure as against on a Command Button? Is it a speed related thing?
Have tried your suggestion, but for some reason when a textbox is null "blnError" still shows "blnError = False" and not "blnError = True"! WHY?? Is it because at the very beginning of the code I have
Expand|Select|Wrap|Line Numbers
  1. Dim blnError As String
  2. blnError = False
Expand|Select|Wrap|Line Numbers
  1. 'The correct Syntax should be:
  2. Dim blnError As Boolean
  3. blnError = False
I meant to ask how you "Formatted and Tagged" the script to make it easier to read, also what is the benefit of putting the script in the "Before Update" event procedure as against on a Command Button? Is it a speed related thing?
The BeforeUpdate() Event of the Form fires before the actual data present on the Form is Saved to the underlying Record Source and is the logical location for Validation Code. You 'Format' and 'Tag' code segments by the use of Indentations and the Code Tags present in Edit Mod (#). Select a specific code block, then click on the # sign and designate the code context as text, vb, sql, etc.

http://www.thescripts.com/forum/faq...._read_and_post

boliches, there appears to numerous problems with your code segment, too many for a back-and-forth conversation. If you like, you can send me the Database as an E-Mail Attachment and I'll have a good look at it when I get a chance. The only problem is that it will not be anytime soon and the code itself is not simply a couple of lines. Let me know what you would like to do.
Nov 4 '07 #8
Have amended the syntax, but still am failing to get the blnError = False to blnError = True when a text box is "Null". What am I doing wrong?

Thanks for the update on Formatting etc.

Regards
Nov 4 '07 #9
Have amended the syntax, but still am failing to get the blnError = False to blnError = True when a text box is "Null". What am I doing wrong?

Thanks for the update on Formatting etc.

Regards

Thanks for your interest in my problem, but the database is quite sizeable and may be difficult for me to get you to where the problem is within the project.

My main issue here is that I want to alert a user that info is missing from a form, and therfore (via a msgbox) inform that user which items are missing! Have I gone about it in totally the wrong way? If so could you please advise.

Many thanks. (Really appreciate your time!)
Nov 4 '07 #10
ADezii
8,834 Expert 8TB
Thanks for your interest in my problem, but the database is quite sizeable and may be difficult for me to get you to where the problem is within the project.

My main issue here is that I want to alert a user that info is missing from a form, and therfore (via a msgbox) inform that user which items are missing! Have I gone about it in totally the wrong way? If so could you please advise.

Many thanks. (Really appreciate your time!)
My advice to you would be the following:
  1. Place the code in the BeforeUpdate() Event of the Form.
  2. Change the Declaration of blnError as previously indicated.
    Expand|Select|Wrap|Line Numbers
    1. Dim blnError As Boolean
  3. Evaluate each If...End If Statement in turn, and if the results are correct, move to the next If..End If (will illustrate shortly).
  4. This Method is time consuming but effective, and eventually should produce the desired results.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_BeforeUpdate(Cancel As Integer)
    2. Dim objPDF As New PDFClass
    3. Dim IngResult As Long
    4. Const PDFENGINE_PDF995 = 5
    5. Dim stFaxNo As String
    6. Dim rptFaxDeal As String
    7. Dim strBroker As String
    8. Dim strTable As String
    9. Dim strError As String
    10. Dim blnError As Boolean 
    11. strBroker = Forms!frmMainForm.Text265
    12. strTable = "tblDeals" + strBroker
    13. blnError = False
    14.  
    15. strError = "Please complete the following:" & vbCrLf
    16.  
    17. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
    18.   blnError = True
    19.   strError = strError & "Vehicle Details" & vbCrLf
    20. Else
    21.   blnError = False
    22. End If
    23.  
    24. 'Avoid Errors, not interested in Saving - only Testing
    25. Cancel = True
    26. End Sub
    27.  
  5. Enter a Value in [Forms]![frmDeal]![frmDealsSub].Form![Text62], blnError should return False, if it does add the next If...End If Statement and continue this pattern until all conditions have been tested.
Nov 4 '07 #11
I think I now know why this is failing!

Expand|Select|Wrap|Line Numbers
  1. Dim blnError As Boolean
  2. blnError = False
  3.  
  4. strError = "Please complete the following:" & vbCrLf
  5.  
  6.   If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text118]) Then
  7.      blnError = True
  8.           strError = strError & "No. of Owners" & vbCrLf
  9.   Else
  10.      blnError = False
  11.         End If
  12.  
  13.  If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Colour]) Then
  14.     blnError = True
  15.             strError = strError & "Vehicle Color" & vbCrLf
  16.   Else
  17.     blnError = False
  18.        End If
  19.  
  20.  If blnError = True Then                
  21.                     MsgBox strError, vbOKOnly + vbCritical, "Stop!"
  22.                              Exit Sub
  23.    Cancel = True
  24.        End If
  25. End Sub
  26.  
This code works fine when all data is missing! However I think the problem is that as the code unfolds the blnError will equal what ever the final textbox is! For example if the final textbox (in the above case "Colour") has text in it then blnError = False. If the initial textbox (Text118) is Null the blnError will need to be True to action the msgbox. It is being overriden by the next textbox.

Hope this makes sense, but is there a resolution? Would some sort of loop work?? Would not have a clue myself!
Nov 4 '07 #12
I think I may have it:

Expand|Select|Wrap|Line Numbers
  1. Dim strError As String
  2. Dim blnError As Boolean
  3.  
  4. blnError = False
  5.  
  6.     strError = "Please complete the following:" & vbCrLf
  7.  
  8.             If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text118]) Then
  9.                   blnError = True
  10.                       strError = strError & "No of Owners" & vbCrLf
  11.                              End If
  12.  
  13.             If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Colour]) Then
  14.                   blnError = True
  15.                       strError = strError & "Colour" & vbCrLf
  16.                              End If
  17.  
  18.            If blnError = False Then MsgBox "All Completed"
  19.            If blnError = True Then
  20.                  MsgBox strError, vbOKOnly + vbCritical, "Stop!"
  21.                          Exit Sub
  22.            End If
  23.  
What do you think?

Really appreciate your help on this matter, youve been very helpful.
Nov 4 '07 #13
ADezii
8,834 Expert 8TB
I think I now know why this is failing!

Expand|Select|Wrap|Line Numbers
  1. Dim blnError As Boolean
  2. blnError = False
  3.  
  4. strError = "Please complete the following:" & vbCrLf
  5.  
  6.   If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text118]) Then
  7.      blnError = True
  8.           strError = strError & "No. of Owners" & vbCrLf
  9.   Else
  10.      blnError = False
  11.         End If
  12.  
  13.  If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Colour]) Then
  14.     blnError = True
  15.             strError = strError & "Vehicle Color" & vbCrLf
  16.   Else
  17.     blnError = False
  18.        End If
  19.  
  20.  If blnError = True Then                
  21.                     MsgBox strError, vbOKOnly + vbCritical, "Stop!"
  22.                              Exit Sub
  23.    Cancel = True
  24.        End If
  25. End Sub
  26.  
This code works fine when all data is missing! However I think the problem is that as the code unfolds the blnError will equal what ever the final textbox is! For example if the final textbox (in the above case "Colour") has text in it then blnError = False. If the initial textbox (Text118) is Null the blnError will need to be True to action the msgbox. It is being overriden by the next textbox.

Hope this makes sense, but is there a resolution? Would some sort of loop work?? Would not have a clue myself!
You could greatly simplify your If...End If logic via:
  1. See if data in a Field is missing, if it is display an appropriate Message Box, if not drop through to the next If...End If Statement.
  2. If the data was missing, set Focus to the Field with the missing data.
  3. If the data was missing, Exit the BeforeUpdate() Event..
Expand|Select|Wrap|Line Numbers
  1. If IsNull([Forms]![frmDeal]![frmDealsSub].Form![Text62]) Then
  2.   Msgbox <missing data appropriate Message Box>
  3.   [Forms]![frmDeal]![frmDealsSub].Form![Text62].SetFocus
  4.     Exit Sub
  5. End If
Nov 4 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Steven James Samuel Stapleton | last post by:
Will calling ksort() on an array speed up it's access? For example, I have the array $file_index, which is accessed by a key (the entry id) and has two sub elements in a one dimensional array...
0
by: pilar | last post by:
Hi All, It is possible to restrict data entry for 2 fields at the same time?, i know how this may sound for you, please don't insult me (just kidding, this is a great newsgroup). In my first...
2
by: David C. Barber | last post by:
upsized an MDB to ADP/SQL Server 2000 under Access 2000. All the DAO code that I've changed to ADO code is working fine, HOWEVER the form Record Source itself does not seem willing to return data....
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
8
by: Martin | last post by:
I hope not, but, I think the answer to this question is "it can't be done". Northwind sample database. Orders form. Go to a new record. Select a customer in "Bill To:" Don't enter any...
1
by: jhutchings | last post by:
Hello all, I have a form I designed for data entry. However, when I set the form properties to Data Entry mode, the form completely disappears for Access 2000 users. All they see is a white blank...
3
by: Hamed | last post by:
Hello I have a Data Entry Form having some controls including a TextBox. When the user types an entry, I query a table and if it was entered before, I ask the user (using ShowModal method of a...
2
by: seltzer | last post by:
I am using Access 2000 but I also have the 2003 version. I am working on creating a data entry form in Access for a research study. Since there is a maximum of 255 fields per table in Access, I...
8
by: Peted | last post by:
I have an amazing problem which i think i have no hope of solving Im working with a c# dot net module that is hosted by and runs under a delphi form envrioment. Dont ask me how this insanity has...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.