Visual Studio Datetimepicker - sql

I'm working on a program that will add records to an access database once a VB form has been completed. Once stored the information can be searched and printed as needed. I'm having no issues with that.
The problem I'm having is when a Windows 7 computer submits information it changes the format of my DateTimePicker.
Ex. The Data was added using the date Wednesday, April 4, 2018. But on windows 7 if a user were to use the same exact criteria from the DateTimePicker and search by it the field would populate as Wednesday, April 04, 2018. Windows 7 adds a 0 placeholder to the front of what day it is when using the DateTimePicker. Is there a way to set the DateTimePicker in Visual Studio to override how Windows 7 is changing this value?
This is the line where my search adapter pulls information based on the DateTimePicker:
da = New OleDbDataAdapter("SELECT * FROM " + ComboBox1.Text + " WHERE Date like '%" & CodeText.Text & "%'", myConnection)
Thanks in advance.

Correction, I got it working. I don't know why I didn't think of it but I just set the DateTimePicker to a custom format and now it works between Win 10 and Win 7. Thanks!
Also it queries just fine, Steve.

Related

Format specifiers for VB.NET in Visual Studio in 2013

I've been trying to find a way to render \r\n as actual newlines in the immediate and command window in my VB.NET 4.5.1 application. I came across this question which teaches about the nq specifier, but it appears to apply only to C#. In VB.NET, nq doesn't even appear to work because I get Expression expected printed back out at me.
Is there a different way to make newlines actually show as separate lines in the immediate or command window in VB.NET?
An easier way in visual studio 2015 is to do this in the debug window:
?string,nq
You can also do the debug version in earlier versions of VS
?System.Diagnostics.Debug.Print(string,nq)
I've discovered that the solution is to use System.Diagnostics.Debug.Print(). To reproduce the original issue, entering this into the Immediate window...
? "a" & vbCrLf & "a"
...just returns this:
"a a"
However, using this...
System.Diagnostics.Debug.Print("a" & vbCrLf & "a")
...actually shows the newline:
a
a

How to change/set DateTimePicker value

I am trying to set / change the DateTimePicker value (using vb.net) but can't work out how to do it.
I have added the control to the page and I have tried using the following code but it doesn't work and I can't work out how to set the value during run-time.
DateTimePicker1.Value = Now.Day & "-" & Now.Month & "-" & Now.Year
The format of the control is set to Long and it looks like this when first loaded:
Tuesday, February 26, 2013
But I can't work out how to change it.
The error I get based on my code above is:
Conversion from string "26-2-2013" to type 'Date' is not valid.
Anyone got any ideas ?
I ended up getting it working by doing the following:
DateTimePicker1.Value = New Date(2013, 2, 26)
I was loading the value wrong.
Add the following code on Form Load Event to set the date time picker value to today:
DateTimePicker1.CustomFormat="dd-MM-yyyy"
DateTimePicker1.Value=Now()

ms access visual basic 2010 report does not order by

this one is the screenshot on the visual basic report. as you can see it starts at august then december then february but it i already group by it on the access which is this.
this is a query in the access im not sure if i did the right thing but i is already ordered by the earliest .
here is the sql code from the ms access
SELECT MonthName(Month([Date_sold])) & ' ' & Year([Date_sold]) AS Month_Sold, Sum(tblSell.Total_Price) AS Total_Earnings, Sum(tblSell.Quantity_Bought) AS Total_Medicine_Sold, tblSell.Generic_name, tblSell.Brand_Name
FROM tblSell
GROUP BY MonthName(Month([Date_sold])) & ' ' & Year([Date_sold]), tblSell.Generic_name, tblSell.Brand_Name, Year([Date_sold]), Month([Date_sold])
ORDER BY Year([Date_sold]), Month([Date_sold]);
in short is it doesnt order by on my report on the visual basic it should show february first like the one on ms access but it shows august which is different.
Order by, I believe, gets over written by the reports Order By property in the Data tab, on the property sheet. Either set it there or make sure it is empty. Then set the reports properties like this:
Me.OrderBy = "[SomeField], [AnotherField]"
Me.OrderByOn = True
EDIT:
All Microsoft products allow developers access to a development environment using a language called VBA (Visual Basic for Applications). You can use this language to write programs and macros to enhance products. Take a look here, although it's a bit old it may still be relevant: http://visualbasic.about.com/od/learnvba/l/aa030803b.htm
For you, you will need to add the code I suggested to the OnLoad event of the report. To do this:
Open Access.
Open your report in Design View.
On the left hand side, you should see a tab called Property Sheet
Select the Event Tab
in the OnLoad event, click the "..." (ellipsis) button
This will bring up the VBA code.
Add This:
Private Sub Report_Load()
Me.OrderBy = "[SomeField], [AnotherField]"
Me.OrderByOn = True
End Sub
Try that and see if it works.
The reason why is it not sorting (I am having this same problem at work doing some shipment order reports) is because the code is not reading the date. It will list them aplhabetically because it is a text field and not a short date. I just went to the parameters and was able to fix it there.

From Access 2002 to Access 2010 Conversion failed when converting date and/or time from character string

I am working on this Access 2002 database. It uses linked servers to SQL Server 2008. I am having a problem where in load of the main form it does a DLookup and looks at a date.
EndDate = Nz(DLookup("End_Date", "Employee", "EmpID= " & EmpID & " AND End_Date IS NOT NULL AND End_Date < #" & Now & "#"), "")
Now this works fine in Access 2002, but in Access 2010 I get the:
Conversion failed when converting date and/or time from character string
Here's the kicker though, it works in Access 2010 for one user: myself. No other users does it work for and also other installations with Windows 7 and the Access 2010 Runtime work fine. On the same machine the MDB works correctly also. If I replace the Pound signs with single quotes like in SQL Server it runs fine on the 2010 machine but no longer works on 2002 (duh).
It's just been wracking my brain and normally I have been able to get it to work by uninstalling all of Office and then reinstalling and making sure the SP1 for the Access Runtime was installed last.
Instead of transforming the value of Now() to a string in your DLookup, just let the db engine determine Now() for itself.
EndDate = Nz(DLookup("End_Date", "Employee", _
"EmpID= " & EmpID & " AND End_Date IS NOT NULL AND End_Date < Now()"), "")
That approach does not depend on a conversion between Date/Time and string and back again, so will avoid the problem you reported.
If you want to examine how the original DLookup gave different results, try something like this on the different machines:
Dim strCriteria As String
strCriteria = "EmpID= " & EmpID & " AND End_Date IS NOT NULL" & _
" AND End_Date < #" & Now & "#"
Debug.Print "strCriteria: " & strCriteria
EndDate = Nz(DLookup("End_Date", "Employee", strCriteria), "")
After running that code, go to the Immediate window (Crtl+g) and inspect the value of strCriteria.
Note that the type of date / time field that you are using in SQL Server may cause problems, which could explain the difference between versions.
Access 2010 provides limited support for four new date/time data types
that were added in SQL Server 2008:
TIME
DATE
DATETIME2
DATETIMEOFFSET
-- http://office.microsoft.com/en-us/access-help/create-an-access-project-HA010341589.aspx#_Toc257281378
If you are storing the dates in SQL server as the data type “Date” or
“Date2” try changing them to “DateTime” I had this problem linking
data from SQL server 2008R2 to access 97, access did not see it as a
date and treated it like text
-- MS-Access front-end does not recognise dates from SQL Server
As an aside, there is no need for End_Date IS NOT NULL, once you add another criterion, null values will be excluded unless you specifically include them.

ShortdateFormat of application changes if run as Administrator

I have a VB.net application that has datagridviews and date control in windows forms. I have the short date format set in the date controls and short date format is some columns of the datagridview.
If I run the application on server 2008 it picks up the wrong short date format. I have the server 2008 regional settings as "en-AU" but for some reason the app picks up en-US as the current culture.
If I run the app as the Administrator it seems to pick up the proper culture.
Can anyone give me a reason as to why it could be doing that?
I tried setting the locale manually by doing
Dim c As Globalization.CultureInfo = New Globalization.CultureInfo(_Culture)
System.Threading.Thread.CurrentThread.CurrentCulture = c
System.Threading.Thread.CurrentThread.CurrentUICulture = c
But the same results.
Regards,
Dasith
What if you specifically set the culture?
Dim c As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US", False)
That goes in the _Load sub of your main form.