?
Solved

to BergJC

Posted on 1998-09-22
4
Medium Priority
?
148 Views
Last Modified: 2010-04-30
It's a detail about my question:
"how to check a form input before saving?"
when user fill out all fields(text boxes)about Presonal Information then He/She will choose SavemnuItem under File menu.I thought if I disable Save Item when form is loaded, and after all fields are filled out eabled it. and give the user ability to save that information.I dontn't konw how to do it.
Regards,
          Kamijp
0
Comment
Question by:kamijp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 1436128
Take the code I sent to your original question and enable/disable the SaveMnuItem on the basis of the Flag variable. Put the code in the KeyPress event for the from and set the form to KeyPreview True

M
0
 
LVL 2

Accepted Solution

by:
BergJC earned 40 total points
ID: 1436129
Place this code inside your MnuFile_click event (or whatever you called your file menu item)

Note: Instead of checking the length of the textboxes, check to make sure the trim$(Text1.Text) property is greater than spaces. If you only check the length, spaces would be allowed to pass through. If your text boxes are not in an array, just check them individually, like so:

Private Sub mnuFile_Click()

SaveMnuItem.Enabled = True
 
If Trim$(Text1.Text) <= "" Then
    SaveMnuItem.Enabled = False
End If

If Trim$(Text2.Text) <= "" Then
    SaveMnuItem.Enabled = False
End If

'and so on....

End Sub

If your textboxes are in an array, just loop through each one, using the same code I gave above. Try that, and if you need more help, just let me know.


0
 

Author Comment

by:kamijp
ID: 1436130
well, I tried what you both told me but it didn't work.I don't know why. so I sent you all my codes(I'm sure you can find lots of unuseful codes...I'm just tring diffrent ideas and options)
 they are not finish yet and I have to go thru them later.Sorry for the Mass!!
If you add any help or correction Please wirte it in BOLD to make it easy for me to undestand where you made the corrections.
Thanks in advance
                    Kami


Option Explicit

Private Sub mnuExitItme_Click()
    Unload Me
End Sub

Private Sub munOpenItem_Click()
 frmCalculator.Show 1
End Sub

Private Sub munSaveItem_Click()
Dim nFileNumber As Integer
Dim sMyData As String
CommonDialog1.CancelError = True
    On Error GoTo ErrHandler
CommonDialog1.Filter = "All Files (*.*)|*.*|Text Files(*.txt)|*.txt"
CommonDialog1.ShowSave
nFileNumber = FreeFile
Open CommonDialog1.filename For Output As #nFileNumber
Write #nFileNumber, sMyData
 
ErrHandler:
  Exit Sub  'User pressed the Cancel button
End Sub

Private Function bInputIsValid(objControl As _
    Control, sMessage As String) As Boolean
    On Error GoTo ErrorHandler
    bInputIsValid = False
    Set objControl = txtLastName
    With objControl
      If Not IsString(.Text) Then
        sMessage = "Last Name must be a string."
        GoTo RoutineExit
      End If
      If .Text = "" Then
        sMessage = _
          "Please enter your Last name."
        GoTo RoutineExit
      End If
    End With
    Set objControl = txtName
    With objControl
      If Not IsString(.Text) Then
        sMessage = "Name must be a string."
        GoTo RoutineExit
      End If
      If .Text = "" Then
        sMessage = _
          "Please enter your name."
        GoTo RoutineExit
      End If
    End With
    Set objControl = txtAddress
    With objControl
      If Not IsString(.Text) Then
        sMessage = "Address must be a string."
        GoTo RoutineExit
      End If
      If .Text = "" Then
        sMessage = _
          "Please enter your Address."
        GoTo RoutineExit
      End If
    End With
    Set objControl = txtCity
    With objControl
      If Not IsString(.Text) Then
        sMessage = "City must be a string."
        GoTo RoutineExit
      End If
      If .Text = "" Then
        sMessage = _
          "Please enter your City."
        GoTo RoutineExit
      End If
    End With
    Set objControl = txtState
    With objControl
      If Not IsString(.Text) Then
        sMessage = "State must be a string."
        GoTo RoutineExit
      End If
      If .Text = "" Then
        sMessage = _
          "Please enter your State."
        GoTo RoutineExit
      End If
    End With
    Set objControl = txtZipCode
    With objControl
      If Not IsNumeric(.Text) Then
        sMessage = "Zip Code must be a number."
        GoTo RoutineExit
      End If
      If .Text <= 0 Then
        sMessage = _
          "Please enter your Zip Code."
        GoTo RoutineExit
      End If
    End With
    Set objControl = txtInvest
    With objControl
      If Not IsString(.Text) Then
        sMessage = "Investment Description must be a string."
        GoTo RoutineExit
      End If
      If .Text = "" Then
        sMessage = _
          "Please enter your Investment Description."
        GoTo RoutineExit
      End If
    End With
    bInputIsValid = True
   
RoutineExit:
  Exit Function
 
ErrorHandler:
  MsgBox Err.Description, vbCritical
  Resume RoutineExit
End Function

0
 
LVL 2

Expert Comment

by:BergJC
ID: 1436131
First, you need to call the bInputIsValid function inside your mnuFile_click event. When you get an error and don't want the user to click on the SAVE menu, be sure to set mnuSaveItem.enabled = FALSE. Also remember to set it back to true right before you call bInputIsValid. One other note: when you are checking to see if a text box is empty, do it like this:

If Trim$(.Text) <= "" Then
     sMessage = _
     "Please enter your City."
     GoTo RoutineExit
End If


0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question