I am trying to automate some SAP Data reports, I am using VisuaL Basic 2017 and SAP Logon 750, all works fine so far but if there's an open connection then a pop up shows with message:
"User XXXXX is already logged" and 3 radio buttons
How can I choose radio button and click either on Confirm Button or Cancel button?
I want to click on the check or button and continue with the same logon.
How can I accomplish that?
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Get_Btn.Click
'=============================
Dim application As Object
Dim SapGui As Object
Dim connection As Object
Dim session As Object
'=================Check Open Sessions==================
'===Activate SAP logon pad engine
application = CreateObject("Sapgui.ScriptingCtrl.1")
'===Initiate one of the predefined SAPlogon pad connection
SapGui = GetObject("SAPGUI")
application = SapGui.GetScriptingEngine
connection = application.OpenConnection("LA TEST", True)
session = connection.children(0)
Try
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "zc98"
session.findById("wnd[0]").sendVKey(0)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
Thanks!!
You can activate the script recording before logging on to SAP. Then you can see which commands are used. In my test example I recognized the following:
...
session.findById("wnd[1]/usr/radMULTI_LOGON_OPT1").select
session.findById("wnd[1]/tbar[0]/btn[0]").press
...
Regards, ScriptMan
Related
I'm in the process of converting some outlook VBA macros to an Add-in. I am having difficulty with my macros that create emails based on a template. I decided to code a simple button to create and display a new email with the subject test.
Everything is working up to displaying the email which doesn't happen.
Private Sub ButtonGenEmail_Click(sender As Object, e As EventArgs) Handles ButtonGenEmail.Click
Me.Close()
Dim objApp As Outlook.Application
Dim objMail As Outlook.MailItem
objApp = Globals.ThisAddIn.Application
objMail = objApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
objMail.Subject = "test"
objMail.Save()
objMail.Display(False)
End Sub
At one point I added msgbox "Done" after objMail.Display(False) and the message never appears.
Thanks in advance
This should obviously work. I'm not so skilled in Outlook but I guess the problem here is that you run it from a form (I see the Me.Close)
Isn't then Outlook blocking to display the mail because the form is still open (I guess modal = ShowDialog())?
I think you will have to either change the form to be not modal (use Show() instead of ShowDialog()) or handle the event after the form is closed, something like
All code below written from top of my mind, so I may miss something
A method from where you initialize the form
Dim frm as new YourForm()
frm.ShowDialog()
if frm.MyState = TheyClickOnButton Then
' Run your mailItem code here
End If
in the form code
Public Enum State
Unknown = 0
TheyClickedOnButton
End Enum
Public Property MyState as State
Private Sub ButtonGenEmail_Click(sender As Object, e As EventArgs) Handles ButtonGenEmail.Click
MyState = TheyClickedOnButton
Me.Close()
End Sub
What I would like to do is after clicking the button14 which is login it would change all the button in all forms text to "sample" I already change the class where the button2 is from private to public but I still get an error
Public Sub button14_Click(sender As Object, e As EventArgs) Handles button14.Click
If textBox2.Text = "sample" And textBox3.Text = "****" Then
Form1.Show()
Me.Hide()
button2.Text = ("sample")
Form1.button2.Text = ("sample")
Else
MsgBox("Sorry, Username or password not found", MsgBoxStyle.OkOnly, "Invalid")
textBox2.Text = " "
textBox3.Text = " "
End If
End Sub
this is form 1
Public Sub button2_Click(sender As Object, e As EventArgs) Handles button2.Click
Login.Show()
Me.Hide()
End Sub
Do people still write VB code? Anyway, the error message is quite clear. You need to make the button public (not just the class).
But, for security reasons, instead of making the button public...I would recommend you to expose a method to change the text of the button, after all, that's all you're doing. You can even mark this method with the Friend access modifier...I think it is the same as internal in C#?
My guess this is winform project.
You can change the access modifier of your button in the form designer. Select your button press F4 for the property grid, find Modifiers and change it to whatever.
I am new here. So apologize in advance if not wording question properly.
I am developing an application (VS2013, Visual Basic) that using multiple menu items in the MenuStrip. When item is clicked the identical function is called - the Tab is created and appropriate form is loaded.
i.e.
Private Sub XXXMNU0039_Click(sender As Object, e As EventArgs) Handles XXXMNU0039.Click
Dim f1 As New frm_B05_01_SalesQuotes
Dim imgnm As String = "XXXMNU0039"
Call XXXTabPages("Sales Quotes", f1, imgnm)
End Sub
Private Sub XXXMNU0040_Click(sender As Object, e As EventArgs) Handles XXXMNU0040.Click
Dim f1 As New frm_B05_03_SalesQuotesReports
Dim imgnm As String = "XXXMNU_Reports"
Call XXXTabPages("Sales Quotes Reports", f1, imgnm)
End Sub
....
I am wondering is there is a way to create a "global" default "on click event" for all menu items that will accomplish the same thing by default. I have all the relevant information for each menu item stored in a table and hope to avoid creating "on click" for each item.
Thanks in advance.
You could have the same handler for the click event of your ToolStripMenuItems.
Just add, after the first Handles XXXMNU0039.Click the event to handle for another ToolStripMenuItem and so on
Oviously, then problem is how to differentiate the various ToolStripMenuItem that calls the same event handler. But in the event arguments there is the Sender object that represent the current ToolStripMenuItem that has called the event.
Just DirectCast to a ToolStripMenuItem and read its name to pass the correct parameter to the XXXTablPages method
Private Sub menuItemHandler_Click(sender As Object, e As EventArgs) _
Handles XXXMNU0039.Click, XXXMNU0040.Click
Dim f1 As New frm_B05_01_SalesQuotes
Dim itm = DirectCast(sender, ToolStripMenuItem)
Dim imgnm As String = item.Name
Call XXXTabPages("Sales Quotes", f1, imgnm)
End Sub
I have two form in my application i am calling two form together from master page.i wrote code in my master page
in top i declared like this
Dim form As New FrmDelivary
Dim frm1 As New FrmrecievedDelivaryRequest
in toolstrip menu event like this:
Dim frm1 As New FrmrecievedDelivaryRequest
frm1.Location = New Point(625, 225)
frm1.MdiParent = Me
frm1.Show()
Dim frm2 As New FrmDelivary
frm2.Location = New Point(965, 0)
frm2.MdiParent = Me
frm.show()
if i press R i want to go my cursor the particular textbox of FrmrecievedDelivaryRequest
if i press D i want to go my cursor the particular textbox of FrmDelivary
How can I do this? i trey something like this in frmMaster_KeyDown event: but same page is showing again. I have already open instance of FrmDelivary, so I don't want to show same page again. I want to just get cursor position to particular textbox of this form
If e.KeyCode = Keys.A Then
form.Show()
form.txtTicket.Focus()
Cursor.Position = form.txtTicket.Location
end if
I am working on vb.net windows application
After
frm1.Show()
place
frm1.txtTicket.Focus()
I don't think you need the Cursor.Position call
Set your frm1 and frm2 variables at the top of the code window so they are accessible from all of the Subs. In your KeyDown event, put
If e.KeyCode = Keys.A Then
frm1.Show()
frm1.txtTicket.Focus()
Cursor.Position = frm1.txtTicket.Location
end if
The problem is that you are instantiating a new copy of the form with the "AS NEW frmDelivery" statement.
How to navigate using WebBrowser Control? I want to open a C:\file1.html... an example code would be appreciated.
The VB code you have is correct, that is an error with the javascript on the page you are loading, so you can use:
Private Sub Command1_Click()
WebBrowser1.Navigate2 "C:\file1.html"
End Sub
But in Form_Load set silent mode, eg:
Private Sub Form_Load()
WebBrowser1.silent = true
End Sub
i first put a webcomponent as mentioned in the post "How do i open a webpage" in vb6 by adatapost
Private Sub Command1_Click()
WebBrowser1.Navigate2 "C:\file1.html"
End Sub
this works but as u click on the button it pops a error..A error has occured on the scirpt of the page , line 6, Error: object expected, url: file:///C:file1/index.html, do u want to continue , yes or NO............................how to come around this error. ??