Solved

to BergJC

Posted on 1998-09-22
4
142 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
  • 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 10 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now