Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code Help

Status
Not open for further replies.

xmeb

Technical User
Jun 5, 2013
89
Hi:

I have been using the following code on a form for months and it worked fine.

Code:
Private Sub DataEntryFormMasterSaveCommandButton_Click()

myReply = MsgBox("Are you sure you want to save this record? You cannot edit data after you save it.", vbYesNo)
     If myReply = vbYes Then
         
RunCommand acCmdSaveRecord

Me.Requery

End If

End Sub

Today I added the following code to the same form.

Code:
Private Sub Form_Open(Cancel As Integer)
Message = "..."
End Sub

Code:
Private Sub Form_Timer()

TextBox = Message
'Get first character
Dim FChar As String
FChar = Left(Message, 1)
'Remove first character
Message = Mid$(Message, 2, Len(Message) - 1)
'Put 1st character at the end of the message.
Message = Message + FChar

End Sub

It to works fine but has created a problem with my save command button.

I did some research and apparently because I added "Option Explicit Public Message As String" to my code for the scrolling text box the save command button now needs a "Dim" statement of some sort which I do not know how to add.

Thanks,

xmeb
 
You should:
- always use Option Explicit
- always Dim every variable
- always compile your code after making a change

Your variable myReply is not Dim'd and should throw and error.

Code:
Dim myReply as Long

In addition I think Message needs to be Dim'd in the module general declaration.

Duane
Hook'D on Access
MS Access MVP
 
I put in the code you suggested as follows but it still does not work.

Code:
Private Sub DataEntryFormMasterSaveCommandButton_Click()

myReply = MsgBox("Are you sure you want to save this record? You cannot edit data after you save it.", vbYesNo)
     If myReply = vbYes Then
         
         Dim myReply As Long
         
RunCommand acCmdSaveRecord

Me.Requery

End If

End Sub

How would I do the second thing you suggested?

Thanks.
 
Howdy xmeb . . .

You don't have to pull out the first character in your rotation:
Code:
[blue]Message = Mid$(Message, 2, Len(Message) - 1) & Left(Message,1)[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
For your message box you may try:

Code:
[blue]
Dim myReply As Long[/blue]

myReply = MsgBox("Are you sure you want to save this record? You cannot edit data after you save it.", vbYesNo)

If myReply = vbYes Then
    RunCommand acCmdSaveRecord
    Me.Requery
End If

or... You don't have to Declare and use [tt]myReply [/tt] at all.
Also, it is nice to provide user with a nice icon of a question, plus make 'No' as a default for Deletes:

Code:
If vbYes = MsgBox("Are you sure you want to save this record? You cannot edit data after you save it.", vbYesNo Or vbQuestion Or vbDefaultButton2, "R U Sure?") Then
    RunCommand acCmdSaveRecord
    Me.Requery
End If

Hint - 'invest' in MZTools for VBA, you will love it. There is a very handy Message Box Assistent.

Have fun.

---- Andy
 
It works fine now. Thank you to all that helped.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top