IanMWheeler
Technical User
Hi there
I am trying to develop a public sub routine to display messages to the users while long bits of code runs.
The idea is I that I declare the string of Text like "reviewing records..." etc in my private sub and pass it out to the public sub routine to display. I have used a sub routine as there is nothing to pass back to the private subroutine
I have tested the code without passing the message string ok, the form opens and returns (seen in debug.print) but now I can not pass the txt, I have googled but all refs seem to be on functions with the line
Call MsgFormSub(strTxt as string)
but when I try this I get error!
if I try - Call MsgFormSub(strTxt)I get a error for the wrong number of arguments!
I have a couple of real basic question also
1. How do I execute my private subroutine in Visual Basic window direct? To run my code I have to go back to access and press the button to trigger the code, this does not seem right.
2. Rather than declaring a rs and writting the txt message to a table there must be a better way of loading the txt message to a text box control direct, but how?
The code is as follows
from the private sub
Private Sub Command88_Click()
Dim strTxt As String
strTxt = "Test Send"
'Go to msgform sub
Debug.Print "goto msgform"
Call MsgFormSub(strTxt)
debug.Print "return msgform"
Public Routine
Public Sub MsgFormSub()
'This code should be passed the msgTxt from another rountine
'The msgTxt should be written to the table then displayed on the form to inform the user wht is going on while longer code runs
Dim stDocName As String
Dim strTxt As String
Dim dbmsg As DAO.Database
Dim msgrst As DAO.Recordset
Dim strmsgSql As String
Dim stLinkCriteria As String
Debug.Print "arrive at sub routine"
strTxt = "Sales Demand Table Written"
Debug.Print strTxt
stDocName = "SystemMessage"
strmsgSql = "SELECT Msgtxt.MsgTxt FROM Msgtxt"
Set dbmsg = CurrentDb()
Set msgrst = dbmsg.OpenRecordset(strmsgSql, dbOpenDynaset)
With msgrst
.Edit
!MsgTxt = strTxt
.Update
End With
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.RunCommand acCmdRefresh
' run a loop to display the message
i = 0
For i = 1 To 100000000
i = i + 1
Next
DoCmd.Close
Debug.Print "End of sub"
End Sub
Many thanks
A person new to crystal with very little training a part from Access based
Regards
Ian
I am trying to develop a public sub routine to display messages to the users while long bits of code runs.
The idea is I that I declare the string of Text like "reviewing records..." etc in my private sub and pass it out to the public sub routine to display. I have used a sub routine as there is nothing to pass back to the private subroutine
I have tested the code without passing the message string ok, the form opens and returns (seen in debug.print) but now I can not pass the txt, I have googled but all refs seem to be on functions with the line
Call MsgFormSub(strTxt as string)
but when I try this I get error!
if I try - Call MsgFormSub(strTxt)I get a error for the wrong number of arguments!
I have a couple of real basic question also
1. How do I execute my private subroutine in Visual Basic window direct? To run my code I have to go back to access and press the button to trigger the code, this does not seem right.
2. Rather than declaring a rs and writting the txt message to a table there must be a better way of loading the txt message to a text box control direct, but how?
The code is as follows
from the private sub
Private Sub Command88_Click()
Dim strTxt As String
strTxt = "Test Send"
'Go to msgform sub
Debug.Print "goto msgform"
Call MsgFormSub(strTxt)
debug.Print "return msgform"
Public Routine
Public Sub MsgFormSub()
'This code should be passed the msgTxt from another rountine
'The msgTxt should be written to the table then displayed on the form to inform the user wht is going on while longer code runs
Dim stDocName As String
Dim strTxt As String
Dim dbmsg As DAO.Database
Dim msgrst As DAO.Recordset
Dim strmsgSql As String
Dim stLinkCriteria As String
Debug.Print "arrive at sub routine"
strTxt = "Sales Demand Table Written"
Debug.Print strTxt
stDocName = "SystemMessage"
strmsgSql = "SELECT Msgtxt.MsgTxt FROM Msgtxt"
Set dbmsg = CurrentDb()
Set msgrst = dbmsg.OpenRecordset(strmsgSql, dbOpenDynaset)
With msgrst
.Edit
!MsgTxt = strTxt
.Update
End With
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.RunCommand acCmdRefresh
' run a loop to display the message
i = 0
For i = 1 To 100000000
i = i + 1
Next
DoCmd.Close
Debug.Print "End of sub"
End Sub
Many thanks
A person new to crystal with very little training a part from Access based
Regards
Ian