Results 1 to 6 of 6
  1. #1
    Join Date
    May 2014
    Posts
    98

    Unanswered: Messages pop up one after other ?

    My problem is I am using this code and MsgBox show up one after other however I want it show first popup for name and then person fills that info and next popup I don't know what I am missing in the code. Please help. I have a form on which people fill half info and scroll forward and open a new record so I am trying to block them doing so.


    Private Sub Form_BeforeUpdate(Cancel As Integer)

    Dim YourName As String

    Dim cboCenter As String




    If IsNull(Me.[YourName]) Then

    Cancel = True

    MsgBox "You must provide Name"

    If (Me.[YourName]) <> "" Then

    Exit Sub

    End If

    End If




    If IsNull(Me.[cboCenter]) Then

    Cancel = True

    MsgBox "You must provide Center"

    If (Me.[cboCenter]) <> "" Then

    Exit Sub

    End If

    End If


    End Sub

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Try this

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    Dim YourName As String
    
    Dim cboCenter As String
    
    
    
    
    If Nz(Me.YourName, "") = "" Then
    
      Cancel = True
    
      MsgBox "You must provide Name"
    
      Exit Sub
    
    End If
    
    
    
    
    
    If Nz(Me.cboCenter, "") = "" Then
    
      Cancel = True
    
      MsgBox "You must provide Center"
    
      Exit Sub
    
    End If
    
    
    End Sub

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    May 2014
    Posts
    98
    Perfect Thanks for the help.

    Can you increase my knowledge and make me understand what you did
    Quote Originally Posted by Missinglinq View Post
    Try this

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    Dim YourName As String
    
    Dim cboCenter As String
    
    
    
    
    If Nz(Me.YourName, "") = "" Then
    
      Cancel = True
    
      MsgBox "You must provide Name"
    
      Exit Sub
    
    End If
    
    
    
    
    
    If Nz(Me.cboCenter, "") = "" Then
    
      Cancel = True
    
      MsgBox "You must provide Center"
    
      Exit Sub
    
    End If
    
    
    End Sub

    Linq ;0)>

  4. #4
    Join Date
    May 2014
    Posts
    98

    concatenating

    One more question

    I am concatenating 2 columns However I want to put value of 2nd in brackets.

    I am using this

    Name: [FirstName] & " " & [EmployeeID}

    Which gives me result as John 2345
    However I want as John (2345)

    Quote Originally Posted by jj2 View Post
    Perfect Thanks for the help.

    Can you increase my knowledge and make me understand what you did

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    try and read the code rather than just post blitheley.
    its part of the analysis process.
    understand what your code is doing. you will only do that by making an attempt to understand.

    if you don't understand the code then be very very wary of using it. although this site is pretty good at deterring scumbags, we do occasionally get them posting malicious code (usually when that happens its in a zip file with an autoexec macro. And just to make it clear Missinglinq ISNT posting malicious code

    Linq's code is good, but my personal preference is to report all errors in one hit (or set the background colour of the controls which have errors. that allows the user to change anythign that is wrong in one pass.
    so for me I'd modify linq's code:-
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim ErrorMessage as String
    ErrorMessage = ""
    Dim YourName As String
    
    Dim cboCenter As String
    
    
    
    
    If Nz(Me.YourName, "") = "" Then
      Cancel = True
      ErrorMessage = "You must provide Name" & vbcrlf
    End If
    
    If Nz(Me.cboCenter, "") = "" Then
      Cancel = True
      ErrorMessage = ErrorMessage &  MsgBox "You must provide Centre" & vbcrlf
    End If
    
    iCancel = True then 'we hit an error, so display the error message
    msgbox (ErrorMessage, vbExclamatiom)
    
    End Sub
    you can change the backgorund colour of the controls indicating those which either MUST have a value or have an incorrect value
    eg
    mycontrol.,backcolor = vbRED

    you'd need to have validation code which set what ever colour is required
    you'd need to set up the colours in the form details ON current event
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Quote Originally Posted by jj2 View Post

    I am concatenating 2 columns However I want to put value of 2nd in brackets.

    I am using this

    Name: [FirstName] & " " & [EmployeeID}

    Which gives me result as John 2345
    However I want as John (2345)
    Name: [FirstName] & " (" & [EmployeeID] & ")

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •