Parameter query run hyperlink & open webpage, for tracking UPS package - ms-access-2007

I have a parameter query that looks up the tracking # for a given customer_order_ID and outputs the tracking# as a website link, as a single record. Please advise me how I can have the link run automatically when the user inputs the customer_order_ID into the parameter query , in order that the user can immediately track the package on the UPS Worldship website. I do not know VBA nor do I know SQL, but I can make macros.
Thank you very much in advance
SELECT T.order_ID, "http://wwwapps.ups.com/WebTracking/processInputRequest?sort_by=status&tracknums_displayed=1&TypeOfInquiryNumber=T&loc=en_us&InquiryNumber1=" & [T].[tracking_number] & "&track.x=0&track.y=0" AS link
FROM tblShipmentDataFromAllCarriers AS T
WHERE (((T.order_ID)=[Please enter customer order ID]));

If you don't need to parse the return data and just want to open the web page, you can use Application.FollowHyperlink. But you don't need to do the concatenation with the URL in the SQL:
SELECT T.order_ID, [T].[tracking_number]
FROM tblShipmentDataFromAllCarriers AS T
WHERE (((T.order_ID)=[Please enter customer order ID]));
Then you could store the rest of the URL as constants:
Const c_strURL1 = "http://wwwapps.ups.com/WebTracking/processInputRequest?sort_by=status&tracknums_displayed=1&TypeOfInquiryNumber=T&loc=en_us&InquiryNumber1="
Const c_strURL2 = "&track.x=0&track.y=0"
...and then execute it like this:
Public Sub DisplayTrackingNumber(ByVal strOrderID As String)
Dim strTrackingNumber As String
strTrackingNumber = DLookup("tracking_number", "tblShipmentDataFromAllCarriers", "[order_ID]=" & strOrderID)
Application.FollowHyperlink strUrl1 & strTrackingNumber & strUrl2
End Sub
You'd then have to have a UI to collect the OrderID from the user (I'd suggest a form with a combo box) and then call this sub.

Related

Is there a simple code to allow certain user(s) access to see command buttons?

Okay, I am having difficulties coding security behind my user form. Let me give you guys the rundown. I created this make table "tblPermissionTypes" that basically has two field in there "ID" & "EmployeeType_ID". The ID field represents Security level of access 0 through 2, and EmployeeType_ID is the title: 0 = Requestor, 1 = Admin, and 2 = Printer.
With that being said I have another table "tblEmployees" with the same field "EmployeeType_ID", I manually set the 0s, 1s, & 2s. This table also contains all employees UserNames
Finally, I have another table "tblPermission" that contains three fields "EmployeeType_ID", "FormName", and "HasAccess"
My end result is being whenever this tblPermission has a Checkbox under the field HasAccess I want to grant access based on the EmployeeType_ID field to communicate back to the table "tblEmployees", but in this case I want them to only be able to see a button that contains that certain form.
Private Sub cmdClick_Click()
Dim strSQL As String
Dim permission As String
If permission = ("fOSUserName") = True Then
Run strSQL
strSQL = "SELECT * FROM tblEmployees WHERE "
strSQL = strSQL & "tblEmployees.Five2 =" & ("fOSUserName") & """, = False
Then
MsgBox "You do not have permission!", vbExclamation
Else'
cmdButton.Visible True
End If
NOTE: fOSUserName, is a function I created basically the same thing as
Environ("UserName")
Debug.Print strSQL
Function calls should not be within quote marks. You construct an SQL statement but then don't properly use it. You declare and use variable permission but don't set the variable - it is an empty string. Need form name as a search criteria. Couple of other syntax errors but they will go away with this suggested code. Run this code in form Open event to disable button and don't even give unauthorized users opportunity to click. Don't annoy them with a popup message that emphasizes their lowly status in hierarchy.
You need to build a query that joins tblEmployees to tblPermission so that UserName, FormName, HasAccess fields are all available then reference that query in search for permission.
A DLookup could serve here.
Me.buttonNameHere.Visible = Nz(DLookup("HasAccess", "queryNameHere", _
"UserName='" & fOSUserName & "' AND FormName='FormNameHere'"), 0)

Retrieve Log In username and output initials based on a table in Access database

I'm improving an old Access database used to log our receiving inspection reports.
There is a textbox in the report labeled "Inspector Initials". A technician, who has now left the company, wrote a code to retrieve the username and output their initials as a default value.
I tried to recover the database built with it but I can not find it.
I tried formulas and macros to pull this data.
I tried codes that found one other sites/forums.
This used to work.
Function UserNameWindows() As String
UserName = Environ("USERNAME")
End Function
I would like to retrieve the login username through Outlook, reference the "Initials" table and output that user's initials.
with the assumption that you are using active directory (which is standard in most business environments)
Public Function UserNameWindows() As String
With GetObject("LDAP://" & CreateObject("ADSystemInfo").Username)
UserNameWindows = .samaccountname
End With
End Function

Creating a form in Access to get the Customer Information

I have created a database named Customer_master in which I have some customer information saved in an MS Access database.
I am trying to create a Form so that I can enter a Mobile Number and click the Search button and get the Customer Name.
The form is created with the Mobile Number & Customer Name as text boxes and a Search button in front of the mobile number.
As I am new to VBA, I think there is some coding issue.
Below is the code I have tried for the Search button:
Private Sub Command6_Click()
Dim strsearch As String
Dim Task As String
'Check if a keyword entered or not
If IsNull(Me.Mobile_Number) Or Me.Mobile_Number = "" Then
MsgBox "Please type in your search keyword.", vbOKOnly, "Keyword Needed"
Else
strsearch = Me.Mobile_Number.Value
Task = "SELECT Customer_Name FROM Customer_Master WHERE ((Mobile_Number Like ""*" & strsearch & "*""))"
Me.RecordSource = Task
End If
End Sub
After I enter the Mobile Number and click on the Search button nothing is happening as I am not getting the name of the customer.
An alternative way to achieve this is to create a new query in access against the datasource, and in the query definition pass the value from your search form to the query, using FORMS!VALUE.
You can then add a button to your form and save the VBA code to execute the query on click. by adding in the line DoCmd.OpenQuery

Search function in VB.NET

This is my line of code to search the information from the database. I am trying to display the result obtained from the execution of this line. Should I just use a message box or use any object to display it? I do not want to use dataset.
ACommanad.CommandText = "SELECT * FROM Students where StudentID =" & DeleteRecordTextBox.Text & ""
Yes. A message box is perfectly acceptable way to display something to the user.

VBA Excel Workbook with Database connection to SQL server need login information

I have an Excel VBA workbook that I have created. It has a control panel page with a button installed to run the VB/ASP script that runs against our SQL Database. I have created text boxes for entry for dates and have used these as input for the VB/ASP script that pulls the individual sheets(Reports). Now, I want to declare the username from ENVIRON ("UserName") then evaluate the username against a list of usernames and return the user_id (aka UserNumber) to the text box on the control panel page (user_id in sql database).
Example: if sjones is logged into windows then evaluate list of Usernames=165?, then
Var1 = Var1 & "OR ( pd.created_by = '" + Sheets("Control Panel").UserNumber.Text + "' ) ) " & vbCrLf
I want to pull reports based on the person logged into Windows at the time to keep others from running the report for anyone but themselves. The worksheet location is open to all users but I want them to only run the reports for the user logged in? There is probably an easier way to do this but I am very weak in VB/ASP. Please help. TIA Conya
Get username first and execute a sql query to get a userID associated with that. The code might looks like:
Public UName, UID as String
Public Sub GetUName()
UName = Environ("USERNAME")
End Sub
Public Sub GetUID()
strSQL = "Select UID from table1 where username=" & "'" UName & "'"
UID = oConn.Execute strSQL
End Sub