How To Stop The Program?
Hi there, i am new to VB, just a quick question really.
If MsgBox("You have selected not to validate the data, it is advised that all data be validated. If you proceed this may result in incorrect data being stored. Do you wich do continue?", vbYesNo + vbQuestion, "Validation") = vbYes Then
Call process
Else
'How do i end the process here?
End
End If
Where i have end above i need something so that if they press No then the program comes back up so that they can edit data?
Do you understand that, sorry if it isnt very clear.
[593 byte] By [
embracex2] at [2007-11-11 10:15:16]

# 4 Re: How To Stop The Program?
ok no problems, sorry.
Option Explicit
'Products is the name of my Global veriable in my module
Dim Orders As OrdersType
'This is the path of the file displayed in the common dialog
Dim Filename As String
'The number of records currently stored
Dim NumOfRecords As Integer
'The way you are comunicating with the file you are creating
Dim ChannelNum As Integer
'The length of the record
Dim RecordLength As Long
Private Sub cmdOpen_Click()
'Opens the Windows browser
CommonDialog1.ShowOpen
'Displys the files path in the ChannelPath text box
txtChannelPath.Text = CommonDialog1.Filename
'Declared the name of the Filename as the data in txtChannelPath
If txtChannelPath = "" Then
MsgBox "Please Select A Path To Save The Data To!"
Call cmdOpen_Click
End If
Filename = txtChannelPath.Text
'The Record Length is the Length of Products in the Global veriable module
RecordLength = Len(Orders)
ChannelNum = FreeFile
'Opens the specified file and stores the file in a random Channel(Storage location)
'Also specifies that the file length(Len) is the size of RecordLength
Open Filename For Random As ChannelNum Len = RecordLength
'This shows that the NumOfRecords is the Length os file(LOF) * ChannelNum / Lenght(Len) * Products
NumOfRecords = LOF(ChannelNum) / Len(Orders)
'Displays NumOfRecords in the lblNumOfRecords
lblNumOfRecords.Caption = NumOfRecords
Close ChannelNum
End Sub
Private Sub cmdAdd_Click()
If txtChannelPath = "" Then
MsgBox "Please Select A Path To Save The Data To!"
Call cmdOpen_Click
End If
If Check1 = Unchecked Then Call ValidationNo
If Check1 = Checked Then Call Validation
End Sub
Private Sub ValidationNo()
If MsgBox("You have selected not to validate the data, it is advised that all data be validated. If you proceed this may result in incorrect data being stored. Do you wich do continue?", vbYesNo + vbQuestion, "Validation") = vbYes Then
Call process
Else
End
End If
End Sub
Private Sub Validation()
'Checks that there is a path selected
If txtChannelPath = "" Then MsgBox "Please Select A Path"
'Checks that OrderID is an intager
If IsNumeric(txtOrderID.Text) Then Orders.OrderID = True Else MsgBox "OrderID Must Be Numeric", vbInformation, "Validation Error"
'Checks that SupplierID is an intager
If IsNumeric(txtSupplierID.Text) Then Orders.SupplierID = True Else MsgBox "SupplierID Must Be Numeric", vbInformation, "Validation Error"
'Checks that ProductID is an intager
If IsNumeric(txtProductID.Text) Then Orders.ProductID = True Else MsgBox "ProductID Must Be Numeric", vbInformation, "Validation Error"
'Checks that Quantity Ordered is an intager
If IsNumeric(txtQuantityOrdered.Text) Then Orders.QuantityOrdered = True Else MsgBox "Quantity Ordered Must Be Numeric", vbInformation, "Validation Error"
'Checks that Date Due is a date
If IsDate(txtDateDue.Text) Then Orders.DateDue = True Else MsgBox "Please enter a valid date!", vbInformation, "Validation Error"
'Checks that all data is valid before calling process
If Orders.DateDue = True And Orders.OrderID = True And Orders.SupplierID = True And Orders.ProductID = True And Orders.QuantityOrdered = True Then Call process
End Sub
Private Sub process()
If IsNumeric(txtOrderID.Text) Then Orders.OrderID = txtOrderID.Text Else Orders.OrderID = 0
If IsNumeric(txtSupplierID.Text) Then Orders.SupplierID = txtSupplierID.Text Else Orders.SupplierID = 0
If IsNumeric(txtProductID.Text) Then Orders.ProductID = txtProductID.Text Else Orders.ProductID = 0
If IsDate(txtDateDue.Text) Then Orders.DateDue = txtDateDue.Text Else Orders.DateDue = 1 / 1 / 1
If IsNumeric(txtQuantityOrdered.Text) Then Orders.QuantityOrdered = txtQuantityOrdered.Text Else Orders.QuantityOrdered = 0
Open Filename For Random As ChannelNum Len = RecordLength
Put ChannelNum, NumOfRecords + 1, Orders
Close ChannelNum
NumOfRecords = NumOfRecords + 1
lblNumOfRecords = NumOfRecords
'Resets the text boxes so they are empty
txtOrderID.Text = ""
txtSupplierID.Text = ""
txtProductID.Text = ""
txtDateDue.Text = ""
txtQuantityOrdered.Text = ""
End Sub
Private Sub EntryFalse()
'Resets the text boxes so they are empty
txtOrderID.Text = ""
txtSupplierID.Text = ""
txtProductID.Text = ""
txtDateDue.Text = ""
txtQuantityOrdered.Text = ""
End Sub
Private Sub cmdQuit_Click()
'Ends the program
End
End Sub
Private Sub cmdBack_Click()
'Hides the current form
Me.Hide
'Shows frmAdminSelect
frmAdminSelect.Show
End Sub
If the user presses no on the msgbox it still does process however i need it so that when no is pressed it aborts so the user can edit the data.
# 7 Re: How To Stop The Program?
onemore quick question.
When i have the msgbox's display the errors in validation as shown below
Private Sub Validation()
'Checks that there is a path selected
If txtChannelPath = "" Then MsgBox "Please Select A Path"
'Checks that OrderID is an intager
If IsNumeric(txtOrderID.Text) Then Orders.OrderID = True Else MsgBox "OrderID Must Be Numeric", vbInformation, "Validation Error"
'Checks that SupplierID is an intager
If IsNumeric(txtSupplierID.Text) Then Orders.SupplierID = True Else MsgBox "SupplierID Must Be Numeric", vbInformation, "Validation Error"
'Checks that ProductID is an intager
If IsNumeric(txtProductID.Text) Then Orders.ProductID = True Else MsgBox "ProductID Must Be Numeric", vbInformation, "Validation Error"
'Checks that Quantity Ordered is an intager
If IsNumeric(txtQuantityOrdered.Text) Then Orders.QuantityOrdered = True Else MsgBox "Quantity Ordered Must Be Numeric", vbInformation, "Validation Error"
'Checks that Date Due is a date
If IsDate(txtDateDue.Text) Then Orders.DateDue = True Else MsgBox "Please enter a valid date!", vbInformation, "Validation Error"
'Checks that all data is valid before calling process
If Orders.DateDue = True And Orders.OrderID = True And Orders.SupplierID = True And Orders.ProductID = True And Orders.QuantityOrdered = True Then Call Process
End Sub
Is there anyway to get it so that the errors are displayed in the same msgbox trather than have 5 msgbox's if there is an error on each check?