I'm attempting to enter a NI number into a Powerbuilder application from an Access DB.
Whenever I attempt to enter "AA123456A" into my application, UFT passes the value in as 123456.
If f_GetAccessFieldValue("NINumber") <> "" Then
PbWindow("w_genapp_frame").PbWindow("Client Details").PbDataWindow("dw_ap010_03_02"). SetCellData "#1","custp_ni_code",f_GetAccessFieldValue("NINumber")
End If
The value from Access is definitely passed in as a string.
Is this a limitation of my application, or is there a simple way to fix this without having to split the string and enter the values using separated variables?
Edit: Just noticed that even sending letters on their own ("AA") does not work.
The solution was to use SendKeys and pass in a variable
If f_GetAccessFieldValue("NINumber") <> "" Then
strNINo = f_GetAccessFieldValue("NINumber")
PbWindow("w_genapp_frame").PbWindow("Client Details").PbDataWindow("dw_ap010_03_02").SelectCell "#1","custp_ni_code"
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys strNINo
WshShell.SendKeys "{TAB}"
End If
Related
I'm running VBA in Word 2016 on Windows 10.
In trying to debug a larger sub, I created a sub after suspecting that there was some issue with the Dir function.
This debugging sub is :
Sub TestDetectFolder() 'with trailing backslash or not
MsgBox Dir("C:\Users\adres\Downloads\Captures") <> ""
End Sub
Now I literally copy/pasted the "Captures" folder's address from Explorer and still, the message box displays "False".
Since the folder exists, shoudln't it return True ?
I've also tried adding a trailing backslash, which doesn't work either
I've created a form that works well with macros running in the background to validate data and then print the document to a specific printer on the network.
The key element of this process is a production number value which I would like to keep a running log of and display in a static status dialog window. In other words, a popup window similar to a MsgBox that would not interfere with other actions on the form, but float on top of the document.
Visual concept of this would be...
User could shift the window away from their work if needed. Close the window if they desired, but pragmatically I want to re-pop/refresh the data in the window each time the background macro completes.
I can't use MsgBox, because it forces a closure of the window before the user can continue working on the document. I just want this visible to the user so they know what was last worked on and the few prior to that.
Any idea what control I might be able to use, or switch to MsgBox that would allow the user to continue working?
Ken...
PS: I found this and am trying to find a way to make this work for me. So far I have managed to get to function in the manner I want, but the lingering issue is how to call this PS script and include the information I need to display.
Alternatives to MsgBox in VBScript - StackOverflow
PPS: I opted to go a slightly different route and release the form with a MsgBox that is displayed at the end of the macro. I describe this in the solution noted below.
Instead of using a MsgBox, please consider using a VBA Userform. They're not much more complicated to use than a MegBox, but you can set them to be Modeless. Modeless dialogs remain open on-screen while you work on the Word document. Here'is Microsoft's page on setting dialogs as Modal or Modeless: Show method
If you search on VBA modeless dialog, you'll find many other helpful pages on the subject.
After doing much research, I've come back to revising my macro to incorporate static variables and a MsgBox at the end to report the last 5 production numbers that have been printed.
To provide a means of bringing up this MsgBox for reference, between printing runs, I created an OnlyNum variable as string and replaced the MsgBox I had for letting the users know they were only to use numbers in this field with that message. The end of that trap diverted the flow to the bottom of the macro (where the MsgBox that displayed the last five print jobs has been placed).
So, when the status MsgBox is displayed as a result of printing it only shows the last five events. If the trap captures it, it shows the message letting the user know to only use numerals and then displays the last five events.
Code reference:
Private Sub CommandButton1_Click()
Dim Prod As String
Dim Temp As String
Dim OnlyNum As String
Static ProdNum1 As String
Static ProdNum2 As String
Static ProdNum3 As String
Static ProdNum4 As String
Static ProdNum5 As String
'Check for only numeric value of TextBox1.Text
If Not IsNumeric(TextBox1.Value) Then
OnlyNum = "only numbers allowed" & vbCrLf & vbCrLf
Cancel = True
GoTo NotToday
End If
'Remove any spaces from TextBox1.Text
Prod = Replace(TextBox1.Text, " ", "")
'If the resulting lenght is equal to 7 Print it.
If Len(Prod) = 7 Then
ActiveDocument.PrintOut
'Update recent production numbers (5 in total)
ProdNum5 = ProdNum4
ProdNum4 = ProdNum3
ProdNum3 = ProdNum2
ProdNum2 = ProdNum1
ProdNum1 = Prod & " - " & Now() ' Insert a new production number with timestamp
TextBox1.Text = "" 'Clear the value of TextBox1.Text to prepare for the next Production number
Else
MsgBox ("Production Numbers must be 7 digits and contain only numerials.")
End If
NotToday:
Application.ActivePrinter = Temp
MsgBox (OnlyNum & ProdNum1 & vbCrLf & ProdNum2 & vbCrLf & ProdNum3 & vbCrLf & ProdNum4 & vbCrLf & ProdNum5)
OnlyNum = "" 'Reset value of OnlyNum
End Sub
i'm a beginner of vbscript , i need you help , my question is how do i do to get a variable from cmd and show it in vbscript for example get a ping from www.google.com and show it in a msgbox in vbscript help me code :
dim cmd,x
set cmd = createobject("wscript.shell")
x= cmd.run("cmd /k ping www.google.com ",1,true)
Get that output and show it in a msgbox later , help me
Here an example of how to do that.
The response of the ping that is checked is in Dutch but that doesn't matter for your case.
Set objExec = CreateObject("WScript.Shell").exec("ping www.google.com")
With objExec
Do While .Status = 0
WScript.Sleep 10
Do While Not .StdOut.AtEndOfStream
WScript.Echo .StdOut.ReadLine
'Check the .StdErr to see if it is at the end of its
'stream. If not, call ReadLine on it
If Not .StdErr.AtEndOfStream Then
.StdErr.ReadLine
End If
Loop
Loop
End With
An advise though, don't begin scripting in vbscript, it's a dead end.
Choose some modern scripting language like Python or still better for beginners: Ruby.
Be sure to use cscript as engine in stead of wscript, execute the following to set that as default.
wscript //H:Cscript
Your vbscript is then one single line
puts `ping www.google.com`
In connection with another, very different project, I am trying to write a VBScript that will, when executed, do the following:
Open an instance of Notepad (as a hidden or minimized window)
Bring the instance of Notepad into focus
Write "Hello world" into the open notepad file
Issue the appropriate alt+S etc. commands to save the file on the Desktop as "PrototypeText.txt"
Close Notepad.
My biggest points of confusion are in steps "2" and especially "4" above. I know how to do all the other things in VBScript. Can anyone help me with these two steps?
Lastly, I realize that there are much more practical ways of accomplishing this, such as AutoHotKey, or writing directly to the *.txt file, in some other language perhaps. Please understand that the above program is a proof-of-concept for another project, not a deliverable in itself.
Your time spend responding is greatly appreciated. A link (that I haven't found yet) that specifies how to do "2" and "4" above would work as well.
In WSH object if you are running vbs in that environment (as is likely) then use appactivate. But a hidden window can't be activated so ...
Again sendkeys in the WSH object can do 4 (but not in a hidden window).
Here's a sample from vbscript help (https://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx) using both commands and note using sleep to give apps the chance to process commands.
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "calc"
WScript.Sleep 100
WshShell.AppActivate "Calculator"
WScript.Sleep 100
WshShell.SendKeys "1{+}"
WScript.Sleep 500
WshShell.SendKeys "2"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 500
WshShell.SendKeys "*3"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 2500
Minimised windows can get the focus.
Use a string like this to get the desktop. Include quotes."%userprofile%\desktop\yourfilename.txt". Quotes are in case there are any spaces.
Also AppActivate returns a code. True if it can or is activated. You can use this to test for dialogs by apactivating the dialog title. It's really Window activating.
Assuming you don't want to change/keep adding to this text file via scripting while it's open the below should work.
Dim objFSO, objFileToWrite, WShell
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WShell = CreateObject("WScript.Shell")
'Create Text File and write to it then close it
Set objFileToWrite = objFSO.CreateTextFile("C:\Users\***YOUR USER ID HERE***\Desktop\PrototypeText.txt", 1)
objFileToWrite.Write "Hello World"
objFileToWrite.Close
'Open newly created and saved text file
WShell.Run("Notepad.exe C:\Users\***YOUR USER ID HERE***\Desktop\PrototypeText.txt")
I'm trying to update some data into a SharePoint document and while trying this in local environment I do not face any issue.
But when I try to do the same in virtual desktop, I couldn't make it. I'm being populated with Windows Alert to key-in username & password. I've tried using 'SendKeys' for this scenario, but it doesn't make sense.
....
SendKeys "abc\ATX123",5
SendKeys "Password1",5
SendKeys "{ENTER}",5
....
This snippet is just passing 'ENTER' without entering ID & Pwd. Can anyone suggest me some possible solution, please?
Finally, I've found a way to achieve this requirement,,,,, bit indirect, but that was the only way I could find at the end.
What I did is simple - just created one windows scripted file 'Logon.vbs' to handle that popup screen and called the vbs in VBA.
Refer to the sample below, if you're looking for something like this:
Windows Script:
'Creating an script object
Set oWSH = WScript.CreateObject("WScript.Shell")
'Activating alert screen
oWSH.AppActivate ("Windows Security")
'Passing the value UserName/UserID
oWSH.SendKeys "USERNAME" 'ensure to complete the username with apropriate domain e.g., abc/A123456
'Changing the focus to password textbox
oWSH.SendKeys "{TAB}"
'Passing the value password
oWSH.SendKeys "PASSWORD"
'Clicking enter to complete the screen
oWSH.SendKeys "{ENTER}"
'Releasing the script object
Set oWSH = Nothing
VBA code to call the VBS script - Logon.vbs:
Shell "WScript C:\Users\ABC\Desktop\Logon.vbs", vbNormalFocus
First of all you'll want to SendKeys "yourString", Boolean. As I know the SendKeys command wants a True or a False as second input.
You could also try "tabbing" from a field to another:
SendKeys "abc\ATX123", True
SendKeys "{TAB}", True
SendKeys "Password1", True
SendKeys "{ENTER}", True
if the first one didn't get get written, maybe the focus is on another component of the userform. Try "tabbing" to find out if your "Username" textbox is yet activated as the UserForm appears. In case it isn't you could also try to set some focus