mrbungle 29 Junior Poster in Training

Hmm, just thinking out loud here-

I have a table called "users", and each row will have a few different users. It will include their name, ID number and some other stuff, and also each "user" will have some stats they need to track. So as mentioned above, the text box they enter a "stat" into will need to be saved in their "users" row.

So I guess I opened up another problem-

Dim SQLStatement As String = "INSERT INTO users(stat1) VALUES('" & Me.txtStat1.Text & "')"

I guess if each user needs to log into the app to ensure their stuff is getting added to their row, then this statement above may also be wrong, because I don't see in there how it adds to any one persons specific row... Also, there is a login box at the start of the app that connects to the MySQL database and confirms their login then lets them in under their ID number (which works fine)...

The users ID number is set as a Primary Key in the database.

Unhnd_Exception commented: "Just Because" I shouldn't have down voted this to begin with. :( +8
mrbungle 29 Junior Poster in Training

So I have a text box in a form. The test box needs to take the value entered and insert it into a column within a row in MySQL.

I know it's connecting to the MySQL online, I have a message box telling me so upon a successful connection. I'm just having problems adding the value. Here's my code:

Public Class frmOptions
    Dim ServerString As String = "server=db4free.net; Port =3306; user id=dailylogmain; password=XXXXXXX; database=dailylogmain;"
    Dim SQLConnection As MySqlConnection = New MySqlConnection

   
 Private Sub frmOptions_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        SQLConnection.ConnectionString = ServerString
        Try
            If SQLConnection.State = ConnectionState.Closed Then
                SQLConnection.Open()
                MsgBox("Connected...")
            Else
                SQLConnection.Close()
                MsgBox("Connection failed")
            End If
        Catch ex As Exception
        End Try
    End Sub


Private Sub btnSaveStats_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Dim SQLStatement As String = "INSERT INTO users(stat1) VALUES('" & Me.txtStat1.Text & "')"

        SaveStats(SQLStatement)


    End Sub
    Public Sub SaveStats(ByRef SQLStatement As String)
        Dim cmd As MySqlCommand = New MySqlCommand
        With cmd
            .CommandText = SQLStatement
            .CommandType = CommandType.Text
            .Connection = SQLConnection
            .ExecuteNonQuery()
        End With
        SQLConnection.Close()
        MsgBox("Record Added")
        SQLConnection.Dispose()

    End Sub

When I try to submit, I'm not getting the messagebox saying "record added", so something is not right. I'm not getting any errors, just nothing is happening.

Does anyone have any ideas?

Unhnd_Exception commented: Just Because. -2
codeorder commented: "Just Because" it's only fair. +10
mrbungle 29 Junior Poster in Training

Yup, that did it- thanks for the snippet!

mrbungle 29 Junior Poster in Training

Good point, I agree with your solution. I guess I should figure out the text parse part of it, as that's where the real problem lies.

This is a good line, no errors

Entry:‡002‡0610‡0650‡0040‡City ~ Unobligated Patrol‡TEST‡

This is bad, this causes errors

Entry:‡002‡0610‡0650‡0040‡City ~ Unobligated Patrol‡TEST
‡
mrbungle 29 Junior Poster in Training

I have a textbox, and it's set to multiline, so a user can enter a few sentences. The problem is, if the user hits the enter button while in the textbox, it's starting a new line. This data is being saved as a text file, and it's causing problems when the text file is loaded back into the app, causing load failures.

I'd like to completely make the enter key useless when the textbox has focus. Or, if they hit enter, it tabs over to another button.

Here is some code I used to make the enter button behave more like a tab-

Private Sub txtCallNotes_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Keys.Enter Then
            Me.btnSubmit.Focus()
        End If
    End Sub

The problem is, the enter button still does a carriage return, causing a new line.

In the properties, Accept Return is False.

Is there any way this can be prevented??

mrbungle 29 Junior Poster in Training

Ahhh, gotcha. I was wondering about that also. Thanks for the code, I'm working on it now.

mrbungle 29 Junior Poster in Training

Good snippet- thanks for that

Quick question- I'm a bit stuck on something-

I have this-

table = New DataTable("OfficerInformation")
        table.Columns.Add("Officer", GetType(String))
        table.Columns.Add("Agency", GetType(String))
        table.Columns.Add("Supervisor", GetType(String))

I'm confused on this part-

table.Rows.Add("a1", "b1")
	table.Rows.Add("a2", "b2")

Those values- what are they? I have 15 columns in a single row, with what could be tens of rows.

mrbungle 29 Junior Poster in Training

Like the title says, I have about 10-15 rows in a local dataset. I need to take any one row, and make it the "default" (on a button click), meaning to take that row and stick it right at the top so it comes up first.

I've been up and down the web for a few days looking at ideas, but I can't get around this one. Do I create a new row at the top, then have it copy the info over, then delete the old row, or is there a cleaner way of doing it? Does anyone have a code snippet they'd like to share?

Thanks in advance!

mrbungle 29 Junior Poster in Training

Thanks for the quick reply Momerath. I got it to work with your suggestion, thanks!

mrbungle 29 Junior Poster in Training

Greetings,

My app saves a bunch of stuff to an XML file. This is my line of code-

Using writer As XmlWriter = XmlWriter.Create("C:\vdx2k\MWS\RE\EXTReportsInbox\TK" & frmCitation.txtCiteNumber.Text & "Traff.xml", settings)

So that saves it at that specific location.

I need to duplicate the XML and have it also save in another location. I've been at this for days, Googling, searching, trying different things and now I need to turn here for help.

Any ideas?

mrbungle 29 Junior Poster in Training

Yup, that did it, thanks!

mrbungle 29 Junior Poster in Training

I have an app that writes to XML. If a text box is filled, then I write that value to the XML doc.

writer.WriteStartElement("VEHICLE_LICENSE_NUMBER") '10-28
            writer.WriteString(frmCitation.txtPlate.Text.ToString)
            writer.WriteEndElement()

If TEST123 is the value in the text box, this is the result.

<VEHICLE_LICENSE_NUMBER>TEST123</VEHICLE_LICENSE_NUMBER>

Question is, if that value in the textbox is empty, and not filled in, how do I not even have that line appear in the XML? I'd like it to disappear unless there's a value.

Does anyone have any ideas?

mrbungle 29 Junior Poster in Training

Dang Codeorder, you've saved the day again! A huge public thanks- this guy has helped me more than anyone can imagine. He's gone above and beyond over and over and over to help me, and it's so much appreciated. Thanks dude!

codeorder commented: If heart.felt comment = True Then Return "thanx":) +12
mrbungle 29 Junior Poster in Training

Need help.

I have a combobox (cmbCharge1) that gets populated by a text file. Inside the combobox, the data inside is laid out like this:

41-1A-1303: EXPIRED REGISTRATION

Now, autocomplete works fine, if I start typing in the statute (like the 41 part). But what I need is for it to autocomplete based of whats after the :

So if I type in EX, then everything starting with EX pops up.

Anyone have a code snippet?

codeorder commented: well written post +1
mrbungle 29 Junior Poster in Training

Man, that code is slick! Codeorder, you are a major help to a lot of people! Folks need to give this guy some rep points, well deserved!

mrbungle 29 Junior Poster in Training

Thanks ShahanDev for your quick reply. Your solution worked for me.

mrbungle 29 Junior Poster in Training

Lets see if I can explain-

I have a text box (rich text box) in a form. Inside the box, some data gets put in there- specifically insurance information.

Normally, the box doesn't need to change color to alert the user there's a problem with the text that's inside, because the information is usually good.

But there are a few phrases that need to alert the user there's a problem.

For example, if the words "Not Found AS OF:" appear anywhere in the box, I need the background to show red. Or, if the words "Letter #1" appear in the box, it needs to show red. Absent of any key words, the box is normal (white).

I thought a simple If/Else statement would do the trick, but it's not.

If txtInsurance.Text = "Not Found: AS OF" Then
            txtInsurance.ForeColor = Color.Red
        Else
            txtInsurance.ForeColor = Color.Black
        End If

I know that says ForeColor, I'm playing around with fore vs BackColor.

Can anyone help?

mrbungle 29 Junior Poster in Training

I found this on the web and used it for my app, with some minor tweaking.

So far so good.

mrbungle 29 Junior Poster in Training

Thanks a lot- that was pretty simple.

mrbungle 29 Junior Poster in Training

I can't seem to figure this out-

I have a single text box that has text in it. When I put the mouse in it and click it, I need the text to clear so new text can go in.

Does anyone have a sample?


TIA

mrbungle 29 Junior Poster in Training

In my form I have a graphic in a picturebox- simple stuff. My application prints a bunch of stuff to an Excel file- everything works perfectly with no problems.

I need the image in the picturebox to print to the Excel sheet. I've tried a ton of code but nothing works. Here's the latest version.

Public myFolder As String = "C:\Program Files\DailyLog\"
Public myLogoImage As String = myFolder & "logo.png"
Dim myLogoImage As Image = Image.FromFile(myFolder & "logo.png")
.Range("C1").Image = myLogoImage

There's no errors, but the image doesn't get printed.

I suspect it *might* have something to do with the image in the picturebox needing to be released because it's currently in use by the app- would that make sense?

Does anyone have any ideas on this?

TIA

mrbungle 29 Junior Poster in Training

It does- thanks- marked as solved.

mrbungle 29 Junior Poster in Training

1) Yes
2) Yes
3) I believe so, whatever the defaults are in Win7/XP
4) It does exist, as it's being used in the app.

From researching this, it seems that there's a permission problem. The file being overwritten is currently in use by the app. So overwriting it while the app is using the image I guess won't work. How do I get the app to release the image so it can be overwritten?

mrbungle 29 Junior Poster in Training

So here's the problem-

My app has an image in it in a picture box. I need the end user to be able to change it. So the code I added below should do that. However, I get the "A generic error occurred in GDI+. while saving"

I understand it as this- possibly an error saving it to C:\?? Because when I save it to a folder such as MyPictures or Pictures it saves A-ok.

Does anyone have a solution? It really needs to go in a folder on c:\

Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click
        Dim dlg As New OpenFileDialog
        With dlg
            .Title = "open"
            '.Filter = "GIF Files (.gif)|*.gif"
            .Filter = "All Files|*.*|Bitmap Files (*)|*.bmp;*.gif;*.jpg"
            .FileName = "logo"
            .ShowDialog()
        End With
        TextBox1.Text = dlg.FileName
        PictureBox1.ImageLocation = TextBox1.Text
    End Sub

    Private Sub btnSaveClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveClose.Click
        If Me.PictureBox1.Image IsNot Nothing Then
            Me.PictureBox1.Image.Save(IO.Path.Combine("C:\DailyLog\", "logo.gif"))
        End If
        Me.Close()
    End Sub
mrbungle 29 Junior Poster in Training

Ok, here's what I've got.

I have a form that exports to an Excel worksheet (sheet1) and it works great, no issues there or anything. It's not a template, just a regular .xlsx spreadsheet, but I use it as my template.

Now, the goal is for the end user to be able to fill out the form, and save it as todays date. How does it get todays date? In the Excel sheet, N2 is todays date, and it gets it from the form. Then save it in a specific folder.

But this doesn't work, because VB (VB2010 in case anyone's interested) won't save the Excel file.

The chunk of code does this (0verly simplified)-

1: Opens Excel
2: Populates it
3: ....... Sits there, not sure what it does after it's populated
4: Save As dialog box comes up, and saves it as todays date based on the value of N2, but the transfer of the data doesn't come with it. The sheet is empty, and I get an error it's corrupt.

I've got some sort of disconnect between where the Excel file is opened and populated, and saved as a new file. I can populate it, and have it open- and it asks if I want to overwrite the "template" file, then I can print it or whatever (printing is a whole other story...)

I don't have a database (I'm not qualified to even touch one) and I'm …

mrbungle 29 Junior Poster in Training

*sigh*

I can't get this to work. My program fills all the values into an Excel spreadsheet- no problems there. What I'd like to do is a print preview/print function. I can't seem to get my code right, all I get are blank pages in the print preview box.

Dim oExcel As Object = CreateObject("Excel.Application")
    oExcel.Workbooks.Open("C:\DailyLogs\DailyLog.xlsx")
    PrintPreviewDialog1.Document = PrintDocument1
    PrintPreviewDialog1.ShowDialog()
    oExcel.Sheet1.PrintPreview()

So as I see it, this should open excel, then navigate to the actual excel file. The print preview dialog should come up, which it does, and the excel sheet1 should be previewing, but it's not? I don't have any errors, just a blank print preview. At least thats how I see it, but obviously I'm wrong because it won't work.

Does anyone have any ideas? I've been up and down the internet with no luck.

Thanks

mrbungle 29 Junior Poster in Training

codeorder, did you get my PM? I'm not sure if it went through, or if it went through 5 times...

mrbungle 29 Junior Poster in Training

Nice website btw.:)

Thanks. I do some websites on the side, I'm a full time deputy sheriff assigned to patrol The whole point of this program I'm trying to write is that we currently use a spreadsheet to log our activities. I hate it. Other deputies hate it. It serves it's purpose ie: admin can get their stats and all, but I kept thinking there has to be a better way to collect this data throughout the shift. The spreadsheet is large and cumbersome. But- this log prints to the spreadsheet because that's what the admin likes. My goal is to make it a bit easier for us guys on patrol to quickly enter this stuff while on the go.

I've removed the file from my server for now. Thanks for your time codeorder- if I ever catch you speeding through my county I'll cut you a break! ;)

mrbungle 29 Junior Poster in Training

Thanks codeorder.

It's not filling in the End time on the preceding row after entering the time on the current row.

By the way- thanks for the help you've given so far. I'm pretty new to this and am struggling to say the least.

I put the entire project up on my site at http://www.robrtaylor.com/DailyLog/DailyLogMaster.zip. If you looked at it, that would be cool, if not, I understand the hesitation in downloading someone's project files from the net and the security risks, etc.

Either way, I'm going to do some reading up on this and see what I can learn from it.

Rob

mrbungle 29 Junior Poster in Training

Thanks for the chunk of code. I implimented it and this is what I got.

First off, my text boxes are laid out as followes:

Start1,End1,Time1,CallType1,Description1,Case1
Start2,End2,Time2,CallType2,Description2,Case2
Start3,End3,Time3,CallType3,Description3,Case3

and so on down to 23.

So I edited your code as follows to match my text box naming scheme-

'// Prerequisites: 3 TextBoxes.
    '// TextBox1 = current start time, TextBox2 = case number, TextBox3 = current time in the start box on the next row

        Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
            If e.KeyCode = Keys.F1 Then
                Dim tempStr As String = TimeOfDay
                tempStr = tempStr.Substring(0, tempStr.Length - 6) '// get only hours and minutes.
            If Start1.Focused Then Start1.Text = tempStr
            If Case1.Focused AndAlso Case1.Tag = "enter Key pressed." Then Start2.Text = tempStr
            End If
        End Sub

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.KeyPreview = True '// important when using keys pressed and having other controls on the Form.
        End Sub

    Private Sub Case1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Case1.KeyUp
        If e.KeyCode = Keys.Enter Then
            Case1.Tag = "enter Key pressed." '// set the tag to some value.
        End If
    End Sub

F1 key does what it should. So when it goes to the next line, how do I take that new start time and fill in the preceding end time? Do I make sense?

For example

When the case number box is active (say for example Case1), and …

mrbungle 29 Junior Poster in Training

I forgot to mention I'm using VB 2010.

mrbungle 29 Junior Poster in Training

This page from MS helped me a TON in understanding how to accomplish this task-

http://support.microsoft.com/kb/247412

Once I wrapped my head around it it went smoothly. I used the very first method.

mrbungle 29 Junior Poster in Training

Ok, here's what I've got.

In the screenshot, you'll see three things- a start time, end time and total time. So the goal is this-

A user puts in a current start time by hitting F1 at the start of shift. They tab across the end time to the "time field", then go across the row.

Then they enter their case number, then hit F1 again, and it will enter the current time in the start box on the next row, as well as putting that time in the end box in the row above...

And keep doing this down the whole form.

I hope this makes sense. If anyone can think of a better way to do this, I'm all ears. I need help with the code.

mrbungle 29 Junior Poster in Training

Thanks for your reply- so I guess I don't really need to use a third party compiler program to compile my project like InstallShield?

mrbungle 29 Junior Poster in Training

I guess I have two questions (Visual Basic 2010)-

When I run my compiled project, it creates a start menu folder and desktop icon. But there's nothing in the Program Files of my OS. Is it because my project is still small- or something else? Shouldn't it create a folder in the Program Files?

Speaking of creating a folder- I need to create a folder on my C drive when the program is installed, and inside the folder an Excel spreadsheet needs to be deposited (C:\DailyLogs\DailyLog.xlsx). I've been up and down the internet looking for code to accomplish this- maybe I'm not searching right. Can someone point me in the right direction?

TIA

mrbungle 29 Junior Poster in Training

Yes, that totally helped. Thanks a ton!!

mrbungle 29 Junior Poster in Training

My form fields will populate an Excel workbook. No problems there. My question is how do I call it to enter the data into an Excel template I have already created?

The location of the template sits in my C drive- C:\DailyLogs\DailyLog.xlsx

Here's my code so far:

#         

' Here we go. All the data in the form to an Excel sheet. Cross your fingers...
#         Dim oExcel As Object
#         Dim oBook As Object
#         Dim oSheet As Object
#  
#         'Start a new workbook in Excel- this isn't really what I need though, I need it to open a template and populate it.
#         oExcel = CreateObject("Excel.Application")
#         oBook = oExcel.Workbooks.Add
#  
#  
#         'Add data to cells of the first worksheet in the new workbook
#         oSheet = oBook.Worksheets(1)
#         oSheet.Range("A4").Value = Start1.Text
#         oSheet.Range("B4").Value = End1.Text
#         oSheet.Range("C4").Value = Time1.Text
#         oSheet.Range("D4").Value = CallType1.Text
#         oSheet.Range("E4").Value = Description1.Text
#         'etc....
#  
#  
#         'Save the Workbook and Quit Excel
#         oBook.SaveAs("C:\DailyLogs\DailyLog.xlsx")
#         oExcel.Quit()

Everything works fine as far as putting my form fields into a simple spreadsheet. But I have a spreadsheet template I need to use and print. I've been all over the internet for a few days and can't seem to find the right (VB 2010) code I need to pull up the template and fill it with my data.

One variation I did brought up the template, but it didn't fill the cells with my data- it also pulled …