A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

VB Coding Assistance



 
 
Thread Tools Display Modes
  #1  
Old October 30th, 2008, 04:35 PM posted to microsoft.public.access
Bunky
external usenet poster
 
Posts: 374
Default VB Coding Assistance

I am a novice coder trying to learn VB OJT and I am getting no where. I have
a form that the client enters data to go onto the table. I always want the
client to enter certain pieces of data then I validate it through VB code.
My problem right now is that I have made the form dirty and then have a
procedure that occurs beforeupdate event. If the client clicks on the Cancel
and Exit button without saving, I get a message that the client must enter
the user. On clicking on 'OK' it exits as it should but I cannot get it to
quit that display of the msgbox.

The click on the Cancel runs this code.
Private Sub Command56_Click()
DoCmd.CancelEvent
DoCmd.Close
End Sub

and the Before update runs this code.




Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_BUForm_Click

If IsNull(Me.User) Then

MsgBox "Please Enter a Specialistbu."
Me.User.SetFocus
Cancel = True
GoTo Exit_BUForm_Click
End If


If IsNull(Me.AttendDate) Then
MsgBox "Please Enter a valid Datebu."
Me.AttendDate.SetFocus
Cancel = True
GoTo Exit_BUForm_Click
End If

If IsNull(Me.Comments) Then
MsgBox "Please Enter Commentsbu."
Me.Comments.SetFocus
Cancel = True
GoTo Exit_BUForm_Click
End If

Exit_BUForm_Click:
Exit Sub

Err_BUForm_Click:
MsgBox Err.Description
Resume Exit_BUForm_Click
End Sub

Any suggestions will be appreciated greatly!
  #2  
Old October 30th, 2008, 06:37 PM posted to microsoft.public.access
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default VB Coding Assistance

See whether this works any better:

Private Sub Command56_Click()
Me.Undo
DoCmd.Close
End Sub

You might need Me.Undo twice.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Bunky" wrote in message
news
I am a novice coder trying to learn VB OJT and I am getting no where. I
have
a form that the client enters data to go onto the table. I always want
the
client to enter certain pieces of data then I validate it through VB code.
My problem right now is that I have made the form dirty and then have a
procedure that occurs beforeupdate event. If the client clicks on the
Cancel
and Exit button without saving, I get a message that the client must enter
the user. On clicking on 'OK' it exits as it should but I cannot get it to
quit that display of the msgbox.

The click on the Cancel runs this code.
Private Sub Command56_Click()
DoCmd.CancelEvent
DoCmd.Close
End Sub

and the Before update runs this code.




Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_BUForm_Click

If IsNull(Me.User) Then

MsgBox "Please Enter a Specialistbu."
Me.User.SetFocus
Cancel = True
GoTo Exit_BUForm_Click
End If


If IsNull(Me.AttendDate) Then
MsgBox "Please Enter a valid Datebu."
Me.AttendDate.SetFocus
Cancel = True
GoTo Exit_BUForm_Click
End If

If IsNull(Me.Comments) Then
MsgBox "Please Enter Commentsbu."
Me.Comments.SetFocus
Cancel = True
GoTo Exit_BUForm_Click
End If

Exit_BUForm_Click:
Exit Sub

Err_BUForm_Click:
MsgBox Err.Description
Resume Exit_BUForm_Click
End Sub

Any suggestions will be appreciated greatly!



  #3  
Old October 30th, 2008, 06:56 PM posted to microsoft.public.access
Bunky
external usenet poster
 
Posts: 374
Default VB Coding Assistance

Amazing! Simply Amazing! Thank you, Tremendously!

"Douglas J. Steele" wrote:

See whether this works any better:

Private Sub Command56_Click()
Me.Undo
DoCmd.Close
End Sub

You might need Me.Undo twice.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Bunky" wrote in message
news
I am a novice coder trying to learn VB OJT and I am getting no where. I
have
a form that the client enters data to go onto the table. I always want
the
client to enter certain pieces of data then I validate it through VB code.
My problem right now is that I have made the form dirty and then have a
procedure that occurs beforeupdate event. If the client clicks on the
Cancel
and Exit button without saving, I get a message that the client must enter
the user. On clicking on 'OK' it exits as it should but I cannot get it to
quit that display of the msgbox.

The click on the Cancel runs this code.
Private Sub Command56_Click()
DoCmd.CancelEvent
DoCmd.Close
End Sub

and the Before update runs this code.




Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_BUForm_Click

If IsNull(Me.User) Then

MsgBox "Please Enter a Specialistbu."
Me.User.SetFocus
Cancel = True
GoTo Exit_BUForm_Click
End If


If IsNull(Me.AttendDate) Then
MsgBox "Please Enter a valid Datebu."
Me.AttendDate.SetFocus
Cancel = True
GoTo Exit_BUForm_Click
End If

If IsNull(Me.Comments) Then
MsgBox "Please Enter Commentsbu."
Me.Comments.SetFocus
Cancel = True
GoTo Exit_BUForm_Click
End If

Exit_BUForm_Click:
Exit Sub

Err_BUForm_Click:
MsgBox Err.Description
Resume Exit_BUForm_Click
End Sub

Any suggestions will be appreciated greatly!




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:55 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.