Place a value from VBA on a Popup form message box (1 Viewer)

BamaColtsFan

Registered User.
Local time
Today, 01:06
Joined
Nov 8, 2006
Messages
91
Hi Gang! Ok, so I know that you can't manipulate the appearance of a standard message box and that you need to create a popup form that has what you want and looks all cool. I'm okay with doing this and I have set up a form for my code to call and use. What I don't know how to do is place a value that is determined by the VBA code in the text of the message box form. Basically, in my code sample below, I need the value of strPath to show in the appropriate place of my form (frmFileExportMessage). I can do this fairly easy calling a standard message box. I have left the code for that box below so you can see how I build it now. The popup form has the same text and a command button that closes the form.

So, here is my question: How do you change the text of a form when you call it in VBA?

Code:
Public Function CopyToWorkbook()

'  This is the Baseline Export Function that places all data into the workbook then calls
'  ConvertToFormattedWorkbook from the FileFormatUtility Module

Dim db As DAO.Database
Dim newPath As DAO.Recordset
Dim myDept As DAO.Recordset
Dim newDept As String
Dim myCMD As DAO.Recordset
Dim newCMD As String
Dim myDep As DAO.Recordset
Dim newDep As String
Dim strPath As String
Dim SQL As String
Dim fso As FileSystemObject
Set db = CurrentDb()
Set newPath = db.OpenRecordset("Set_Path")
Set myDept = db.OpenRecordset("qryDepartmentCodes")
Set myCMD = db.OpenRecordset("qryCommandCodes")
Set myDep = db.OpenRecordset("qryDeputyCodes")
Set fso = New FileSystemObject



strPath = newPath!Out_Path & "CombinedTimecards_Crosstab.xls"


' Check to see if the file exists.  If it does, delete it.  Otherwise, do nothing and keep going.

If fso.FileExists(strPath) = False Then
    ''
Else
    Kill (strPath)
End If


        

' LoadFileName

     DoCmd.TransferSpreadsheet acExport, 8, "qryFinalCompSum", strPath, True, "Compliance Summary"

Call ConvertToFormattedWorkbook

DoCmd.OpenForm "frmFileExportMessage"

MsgBox "Report File Export Successful!" & vbNewLine & vbNewLine & _
"Your report file is located at: " & vbNewLine & vbNewLine & _
strPath & "     " & vbNewLine & vbNewLine

End Function

Any advice is greatly appreciated, as always!

THNX!
 

dkinley

Access Hack by Choice
Local time
Today, 00:06
Joined
Jul 29, 2008
Messages
2,016
You can do this by storing the string in an unbound control (hidden) on the calling form, in a variable with full scope, or by the use of the OpenArgs function. The simplest implementation would be the OpenArgs piece.

HTH,
-dK
 

BamaColtsFan

Registered User.
Local time
Today, 01:06
Joined
Nov 8, 2006
Messages
91
Ok, so I think I understand how to use OpenArgs as part of my call to the message form. I believe the code below will place the value of strPath onto the global variable Me.OpenArgs. I have also read several threads on using this method and they seem to indicate I should call this value in the OnLoad event of the form. This is where I am having trouble... I've seen a number of examples and tried most but I guess I'm not getting it. The code below is what I currently have to open this form. What should I have in the OnLoad property of the form?

Code:
DoCmd.OpenForm "frmFileExportMessage", , , , , , strPath
 

dkinley

Access Hack by Choice
Local time
Today, 00:06
Joined
Jul 29, 2008
Messages
2,016
That looks about right.

I would assume most call for the OnLoad because OpenArgs is mostly used to pass something that the db needs to make a decision on about the form and it should occur at this stage in the processing of the form.

It should work for by using Me.OpenArgs in your MsgBox ...

Code:
MsgBox "Your string " & Me.OpenArgs  ...

-dK
 

BamaColtsFan

Registered User.
Local time
Today, 01:06
Joined
Nov 8, 2006
Messages
91
DK - I think I may not have been clear... I don't want to use the MsgBox code (I provided it so you could see what I am doing now). MsgBox opens a popup that I can't format with the same colors and fonts used in the rest of my program so I am using a popup form with the same information. What I want to do is somehow place the value of strPath in the popup form (not the MsgBox) at the appropriate location. Is there a way to use a "token" type replacement value on a form that would swap the token for the value of strPath?

THNX
 

dkinley

Access Hack by Choice
Local time
Today, 00:06
Joined
Jul 29, 2008
Messages
2,016
Errrr .... I was using that as a demonstration that you should be able to use Me.OpenArgs anywhere in the pop-up. :eek:

Now, if you want (because you instantiate other forms using the function) you can set up a (public) variable and assign that variable the contents of OpenArgs for use or manipulation.

-dK
 

BamaColtsFan

Registered User.
Local time
Today, 01:06
Joined
Nov 8, 2006
Messages
91
Well, here I am again being dense...

I have tried a number of variations of calling Me.OpenArgs into my form and I can't get any of them to actually display the value. I'm reasonably sure that they are setting the value, I just can't place that value on the actual form. The latest attempt uses the OnLoad event procedure to run an If statement then place the result in a string value. I just can't get the form to use the string value for anything...


Code:
Private Sub Form_Load()

Dim strPathText As String

If IsNull(Me.OpenArgs) Then
strPathText = "No file was Exported!"
Else
strPathText = Me.OpenArgs
End If

End Sub

So, how do I get the value of strPathText onto my form (displayed only)?

THNX
 

dkinley

Access Hack by Choice
Local time
Today, 00:06
Joined
Jul 29, 2008
Messages
2,016
Okay, think I am with you now. Here is how I have overcame this before using pop-ups in this manner.


Create a label control and set it where you want the 'message' to appear. Say call it lblMessage. Then on the OnLoad event use ...

Code:
If IsNull(Me.OpenArgs) Then
     Me.lblMessage.Caption = "No file was Exported!"
Else
     Me.lblMessage.Caption = Me.OpenArgs
End If

-dK
 

BamaColtsFan

Registered User.
Local time
Today, 01:06
Joined
Nov 8, 2006
Messages
91
Well, the good news is that it is doing something now. The bad news is that it isn't working... I'm getting an error (Compile Error: Method or Data Member Not Found) on the .Compile reference. I am guessing this is because I need to first call the proper library (um... that's what it is in Java, anyway...) into the code so it knows what I am referencing. Trouble is, I have no idea how to do that...

Sorry... that would be the .Caption reference....
 
Last edited:

dkinley

Access Hack by Choice
Local time
Today, 00:06
Joined
Jul 29, 2008
Messages
2,016
Check to make sure it is a label control you put on the form and not a text control.

-dK
 

dkinley

Access Hack by Choice
Local time
Today, 00:06
Joined
Jul 29, 2008
Messages
2,016
Good to go. You could have used a text control, but then you would have to set more properties to make it look like a simple message on the form in your pop-up simulation.

Glad to see it working for you .. good luck in your project!

-dK
 

Users who are viewing this thread

Top Bottom