Error Message Problems

VB6 Error Message Problem

Page 1 of 1

4 Replies - 1081 Views - Last Post: 01 July 2010 - 11:26 AM Rate Topic: -----

#1 Chris Smith  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-June 10

Error Message Problems

Posted 30 June 2010 - 02:50 PM

I'm developing a program for a wedding planning company and I'm having problems with the code (below). In the system there is an administratve log in where staff IDs are made, only there are two boxes where you can input the new Id you're saving.

txtIDSave(0) an txtIDSave(1) are in two different fonts, txtIDSave(1) willl only be displayed when a button is pressed and txtIDSave(0) will have its visible value set to false. I wast it to then save the ID put into the box and reset the text in them, otherwhise display the error message detailed below and reset the text boxes.

At the moment the error message will not display and it always saves the text, can anyone help me please?


Private Sub cmdSave_Click()
    Filename = App.Path & "/Staff ID" 'Declairs the file path
    
    If txtIDSave(0).Text = "New ID" Then
        Open Filename For Append As #1 'Open the file to be appended
            Print #1, txtIDSave(1) 'Saved the ID
        Close #1 'Closes the file again
    ElseIf txtIDSave(1).Text = "New ID" Then
        Open Filename For Append As #1 'Open the file to be appended
            Print #1, txtIDSave(0) 'Saved the ID
        Close #1 'Closes the file again
    Else
        intRetVal = MsgBox("Please enter a valid ID to be saved.", vbOKOnl + vbCritical, "Error") 'An error message appears
    End If
    
    txtIDSave(1).Text = "New ID"
    txtIDSave(0).Text = "New ID"
End Sub


Also is there a way to have one button which changes the font on a form?

This post has been edited by Chris Smith: 30 June 2010 - 03:25 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Error Message Problems

#2 Nikhil_07n  Icon User is offline

  • The cheese stands alone..
  • member icon

Reputation: 50
  • View blog
  • Posts: 2,489
  • Joined: 09-January 09

Re: Error Message Problems

Posted 30 June 2010 - 06:54 PM

In what condition the Error Message should be displayed?
Was This Post Helpful? 0
  • +
  • -

#3 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: Error Message Problems

Posted 30 June 2010 - 10:47 PM

From the looks of it you set both boxes to what you test for and thus always, since the one is not visible, will the second condition be true and never will you hit the else condition.

As for changing the font on the form, you can do me.FontName = "Courier New" or whatever font you want to use but using the common dialog control with the .showfont method would be easier to use to select the font name. However, I must warn you, changing the font of the form will not change the font of any controls on the form, so you would have to do that individually or use a for each loop to iterate through the controls...



Good Luck
Was This Post Helpful? 0
  • +
  • -

#4 Chris Smith  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-June 10

Re: Error Message Problems

Posted 01 July 2010 - 07:18 AM

I rewrote my code:

Private Sub cmdSave_Click(Index As Integer)
        Filename = App.Path & "/Staff ID"
    
    If txtIDSave.Text <> "New ID" Then
        Open Filename For Append As #1
            Print #1, txtIDSave
        Close #1
        intRetVal = MsgBox("Your new Staff ID has been saved.", vbOKOnl + vbInfo, "Information")
    Else
        intRetVal = MsgBox("Please enter a valid ID to be saved.", vbOKOnl + vbCritical, "Error")
    End If
    
End Sub


Now none of it is working, it produces an error about .text in
If txtIDSave.Text <> "New ID" Then
and I dont understand why... The first message box is to be displayed when the ID can be saved, and the second when the ID box has not been changed and the save button is hit by mistake.

So txtIDStaff (the box in which the ID is entered) is changed from "New ID" (the default text in the box) to a code and the save button is pressed, a message box saying "Your new Staff ID has been saved." should be displayed, however if the text still says "New ID" I want it to display the message "Please enter a valid ID to be saved."

Also would using
me.FontName = "Courier New"
change all of my forms text to this font?

This post has been edited by Chris Smith: 01 July 2010 - 11:25 AM

Was This Post Helpful? 0
  • +
  • -

#5 Chris Smith  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-June 10

Re: Error Message Problems

Posted 01 July 2010 - 11:26 AM

Okay I dont understand why but the code now works...

Could someone explain how to use the text function though please?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1