access - reset all comboboxes to itemdata(1) in form - sql

I have about 8 combo-boxes on a form. When a user clicks the button "reset" I would like all the combo boxes to display the first itemdata in the combo box. The code below returns null and doesn't work:
Private Sub Command1_Click()
Me.Combo1.ItemData (1)
Me.Combo2.ItemData (1)
Me.Combo3.ItemData (1)
Me.Combo4.ItemData (1)
Me.Combo5.ItemData (1)
Me.Combo6.ItemData (1)
Me.Combo7.ItemData (1)
Me.Combo8.ItemData (1)
End Sub

If it's MS Access your working with, you'll need to do something like this:
Private Sub Command1_Click()
Me.Combo1.Value = Nothing
Me.Combo2.Value = Nothing
Me.Combo3.Value = Nothing
Me.Combo4.Value = Nothing
Me.Combo5.Value = Nothing
Me.Combo6.Value = Nothing
Me.Combo7.Value = Nothing
Me.Combo8.Value = Nothing
End Sub
Assuming you want to set all the ComboBoxes back to a blank value.

Try this:
Private Sub Command1_Click()
Me.Combo1.SelectedIndex = 0
Me.Combo2.SelectedIndex = 0
Me.Combo3.SelectedIndex = 0
Me.Combo4.SelectedIndex = 0
Me.Combo5.SelectedIndex = 0
Me.Combo6.SelectedIndex = 0
Me.Combo7.SelectedIndex = 0
Me.Combo8.SelectedIndex = 0
End Sub

Something like Me.Combo1.SelectedIndex = 0
Usually...

Related

Textbox not support for property and menthod in VBA ppt

Here is my code
Sub Loadde()
If Slide3.Shapes("MA_VONG") = 1 Then
Slide5.Shapes("Q1").TextFrame.TextRange = Slide6.Shapes("1").TextFrame.TextRange
Slide5.Shapes("Q2").TextFrame.TextRange = Slide6.Shapes("2").TextFrame.TextRange
Slide5.Shapes("Q3").TextFrame.TextRange = Slide6.Shapes("3").TextFrame.TextRange
Slide5.Shapes("Q4").TextFrame.TextRange = Slide6.Shapes("4").TextFrame.TextRange
Slide5.Shapes("Q5").TextFrame.TextRange = Slide6.Shapes("5").TextFrame.TextRange
ElseIf Slide3.Shapes("MA_VONG") = 2 Then
Slide5.Shapes("Q1").TextFrame.TextRange = Slide7.Shapes("1").TextFrame.TextRange
Slide5.Shapes("Q2").TextFrame.TextRange = Slide7.Shapes("2").TextFrame.TextRange
Slide5.Shapes("Q3").TextFrame.TextRange = Slide7.Shapes("3").TextFrame.TextRange
Slide5.Shapes("Q4").TextFrame.TextRange = Slide7.Shapes("4").TextFrame.TextRange
Slide5.Shapes("Q5").TextFrame.TextRange = Slide7.Shapes("5").TextFrame.TextRange
End If
End Sub
At first, it work fine but after that, it showed an error that the Qs (in Slide 5) were not supported
I tried to make it more simple and it still does not work.
Sub Loadde()
If Slide3.Shapes("MA_VONG") = 1 Then
Slide5.Shapes("Q1").TextFrame.TextRange = Slide6.Shapes("1").TextFrame.TextRange
Slide5.Shapes("Q2").TextFrame.TextRange = Slide6.Shapes("2").TextFrame.TextRange
Slide5.Shapes("Q3").TextFrame.TextRange = Slide6.Shapes("3").TextFrame.TextRange
Slide5.Shapes("Q4").TextFrame.TextRange = Slide6.Shapes("4").TextFrame.TextRange
Slide5.Shapes("Q5").TextFrame.TextRange = Slide6.Shapes("5").TextFrame.TextRange
End If
End Sub
Can somebody explain to me what is wrong with this code?
A few suggestions:
First, it's not clear whether you've DIMmed your variables elsewhere.
Next, Slide3.Shapes("some name") = 1 will fail. There's no such property. What exactly are you trying to test for here? The text in the shape or that the shape exists at all? Or something else?
Finally, just to be sure, IS there actually a shape named 1 on Slide6 or are you trying to reference the first shape on the slide, in which case you'd use Slide6.Shapes(1) (not "1" in quotes).
Sub Loadde()
If Slide3.Shapes("MA_VONG") = 1 Then
Slide5.Shapes("Q1").TextFrame.TextRange = Slide6.Shapes("1").TextFrame.TextRange
' ...
ElseIf Slide3.Shapes("MA_VONG") = 2 Then
Slide5.Shapes("Q1").TextFrame.TextRange = Slide7.Shapes("1").TextFrame.TextRange
' ...
End If
End Sub

DataGridViewImageColumn doesn't change value

I'm trying to change the image of a cell inside DataGridViewImageColumn when the value of another cell is OK or NO.
I've created the column with this code
Dim NewImageProd As New DataGridViewImageColumn
NewImageProd.Image = My.Resources.Smile1
NewImageProd.Name = "IMAGE"
NewImageProd.ImageLayout = DataGridViewImageCellLayout.Zoom
NewImageProd.DisplayIndex = 0
NewImageProd.Width = 70
DGDati.Columns.Add(NewImageProd)
Later I've done the check with this code
For Idx = 0 To DGDati.RowCount - 1
Select Case DGDati("OTHERVALUE", Idx).Value.ToString
Case "OK"
DGDati.Rows(Idx).Cells("IMAGE").Value = My.Resources.Smile2
Case "NO"
DGDati.Rows(Idx).Cells("IMAGE").Value = My.Resources.Smile3
End Select
Next
Call DGDati.RefreshEdit()
But nothing happen.
What am I doing wrong?
Use DataGridView.CellFormatting event that occurs when the contents of a cell need to be formatted for display. Using this event you don't need to refresh DataGridView or data.
Private Sub DGDati_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DGDati.CellFormatting
If e.ColumnIndex = -1 Or e.RowIndex = -1 Then Exit Sub
With Me.DGDati
If .Columns(e.ColumnIndex).Name = "IMAGE" Then
If .Rows(e.RowIndex).Cells("OTHER_VALUE").Value = "OK" Then
e.Value = My.Resources.Smile2
ElseIf .Rows(e.RowIndex).Cells("OTHER_VALUE").Value = "NO"
e.Value = My.Resources.Smile3
Else
e.Value = My.Resources.Smile1
End If
End If
End With
End Sub
Also follow advice in the comments to never reuse images from Resources like that.

What is wrong with my subroutines?

So I've been working on this project for a couple of weeks, as I self teach. I've hit a wall, and the community here has been so helpful I come again with a problem.
Basically, I have an input box where a user inputs a name. The name is then displayed in a listbox. The name is also put into an XML table if it is not there already.
There is a button near the list box that allows the user to remove names from the list box. This amends the XML, not removing the name from the table, but adding an end time to that name's child EndTime.
If the user then adds the same name to the input box, the XML gets appended to add another StartTime rather than create a new element.
All of this functions well enough (My code is probably clunky, but it's been working so far.) The problem comes when I try to validate the text box before passing everything through to XML. What I am trying to accomplish is that if the name exists in the listbox on the form (i.e hasn't been deleted by the user) then nothing happens to the XML, the input box is cleared. This is to prevent false timestamps due to a user accidentally typing the same name twice.
Anyhow, I hope that makes sense, I'm tired as hell. The code I've got is as follows:
Private Sub Button1_Click_2(sender As System.Object, e As System.EventArgs) Handles addPlayerButton.Click
playerTypeCheck()
addPlayerXML()
clearAddBox()
End Sub
Private Sub playerTypeCheck()
If playerTypeCBox.SelectedIndex = 0 Then
addMiner()
ElseIf playerTypeCBox.SelectedIndex = 1 Then
addHauler()
ElseIf playerTypeCBox.SelectedIndex = 2 Then
addForeman()
End If
End Sub
Private Sub addMiner()
If minerAddBox.Text = String.Empty Then
Return
End If
If minerListBox.Items.Contains(UCase(minerAddBox.Text)) = True Then
Return
Else : minerListBox.Items.Add(UCase(minerAddBox.Text))
End If
If ComboBox1.Items.Contains(UCase(minerAddBox.Text)) = True Then
Return
Else : ComboBox1.Items.Add(UCase(minerAddBox.Text))
End If
End Sub
Private Sub addPlayerXML()
If System.IO.File.Exists("Miners.xml") Then
Dim xmlSearch As New XmlDocument()
xmlSearch.Load("Miners.xml")
Dim nod As XmlNode = xmlSearch.DocumentElement()
If minerAddBox.Text = "" Then
Return
Else
If playerTypeCBox.SelectedIndex = 0 Then
nod = xmlSearch.SelectSingleNode("/Mining_Op/Miners/Miner[#Name='" + UCase(minerAddBox.Text) + "']")
ElseIf playerTypeCBox.SelectedIndex = 1 Then
nod = xmlSearch.SelectSingleNode("/Mining_Op/Haulers/Hauler[#Name='" + UCase(minerAddBox.Text) + "']")
ElseIf playerTypeCBox.SelectedIndex = 2 Then
nod = xmlSearch.SelectSingleNode("/Mining_Op/Foremen/Foreman[#Name='" + UCase(minerAddBox.Text) + "']")
End If
If nod IsNot Nothing Then
nodeValidatedXML()
Else
Dim docFrag As XmlDocumentFragment = xmlSearch.CreateDocumentFragment()
Dim cr As String = Environment.NewLine
Dim newPlayer As String = ""
Dim nod2 As XmlNode = xmlSearch.SelectSingleNode("/Mining_Op/Miners")
If playerTypeCBox.SelectedIndex = 0 Then
newMinerXML()
ElseIf playerTypeCBox.SelectedIndex = 1 Then
newHaulerXML()
ElseIf playerTypeCBox.SelectedIndex = 2 Then
newForemanXML()
End If
End If
End If
Else
newXML()
End If
End Sub
Private Sub nodeValidatedXML()
If playerTypeCBox.SelectedIndex = 0 Then
minerValidatedXML()
ElseIf playerTypeCBox.SelectedIndex = 1 Then
haulerValidatedXML()
ElseIf playerTypeCBox.SelectedIndex = 2 Then
foremanValidatedXML()
End If
End Sub
Private Sub minerValidatedXML()
If minerListBox.Items.Contains(UCase(minerAddBox.Text)) = False Then
appendMinerTimeXML()
End If
End Sub
Private Sub appendMinerTimeXML()
Dim xmlSearch As New XmlDocument()
xmlSearch.Load("Miners.xml")
Dim docFrag As XmlDocumentFragment = xmlSearch.CreateDocumentFragment()
Dim cr As String = Environment.NewLine
Dim newStartTime As String = Now & ", "
Dim nod2 As XmlNode = xmlSearch.SelectSingleNode("/Mining_Op/Miners/Miner[#Name='" & UCase(minerAddBox.Text) & "']/StartTime")
docFrag.InnerXml = newStartTime
nod2.AppendChild(docFrag)
xmlSearch.Save("Miners.xml")
End Sub
And lastly, the clearAddBox() subroutine
Private Sub clearAddBox()
minerAddBox.Text = ""
End Sub
So, I should point out, that if I rewrite the nodeValidated() Subroutine to something like:
Private Sub nodeValidatedXML()
If playerTypeCBox.SelectedIndex = 0 Then
appendMinerTimeXML()
ElseIf playerTypeCBox.SelectedIndex = 1 Then
appendHaulerTimeXML()
ElseIf playerTypeCBox.SelectedIndex = 2 Then
appendForemanTimeXML()
End If
End Sub
then all of the XML works, except it adds timestamps on names that already exist in the list, which is what i'm trying to avoid. So if I haven't completely pissed you off yet, what is it about the minerValidated() subroutine that is failing to call appendMinerTimeXML()? I feel the problem is either in the minerValidated() sub, or perhaps clearAddBox() is somehow firing and I'm missing it? Thanks for taking the time to slog through this.
Edit: Clarification. The code as I have it right now is failing to append the XML at all. Everything writes fine the first time, but when I remove a name from the list and then re-add, no timestamp is added to the XML.
You need to prevent the user accidentally typing the name twice.(Not sure if you mean adding it twice)
For this I believe you need to clear the minerAddBox.Text in your addminer() if this line is true.
minerListBox.Items.Contains(UCase(minerAddBox.Text)) = True
minerAddBox.Text = ""
Return
Now it will return back to your addplayerXML which will Return to your clearbox(), since you have this in your addplayerXML()
If minerAddBox.Text = "" Then
Return
Now you get to your clearbox() (Which is not really needed now since you cleared the minerAddBox.Text already)
when I remove a name from the list and then re-add, no timestamp is added to the XML.
your minerValidatedXML() is true, because you are not clearing the textbox when you re-add a name to the list box. Or you may need to remove the existing listbox item if it is the same as the textbox
If minerListBox.Items.Contains(UCase(minerAddBox.Text)) = True Then
minerListBox.Items.remove(UCase(minerAddBox.Text))

What else can cause an AxWindowsMediaPlayer to play?

I have a button in my program that grabs a bunch of information from a DataGridView object (volume, url, delay, etc) and using that, it plays a file. I'm trying to get the delay to work (wait x number of seconds before playing) and I'm pretty it will work, but whenever I press the button, the play starts immediately. There is no Ctlcontrols.play() anywhere in the program except after the delay, so I have no idea what is causing it to play.
I explained my problem a little bit more in comments. Sorry if I didn't explain my code very well. If you could just tell my what else could be causing my player to start immediately, that would probably be enough.
'snd_btn_go is the button that is supposed to start it.
'This sub doesn't matter as much for the problem, it will just go to SndCueGO() if both numbers are in the valid range.
Private Sub snd_btn_go_Click(sender As Object, e As EventArgs) Handles snd_btn_go.Click
Dim cue1 As Integer
Dim cue2 As Integer
cue1 = If(Integer.TryParse(snd_txt_cue_1.Text, cue1), Int(snd_txt_cue_1.Text), snd_num1)
If snd_txt_cue_2.Text <> "" Then
cue2 = If(Integer.TryParse(snd_txt_cue_2.Text, cue2), Int(snd_txt_cue_2.Text), snd_num2)
Else
cue2 = -1
End If
If (cue1 <= dgSound.Rows.Count - 1 And cue1 > 0) Then
SndCueGO(cue1, cue2)
End If
End Sub
'This sub pulls all the info from the correct row in the DataGrid and assigns it to a list. It'll check if the start volume and end volume are the same and if they're not, it'll fade to the end volume.
Private Sub SndCueGO(cue1, cue2)
Dim cues() = {cue1, cue2}
snd_num1 = cue1
Dim cuedata1 = snd_ds.Tables(0).Rows(cue1 - 1)
Dim cuedata2 = snd_ds.Tables(0).Rows(cue1 - 1)
If cue2 <> -1 Then
snd_num2 = cue2
cuedata2 = snd_ds.Tables(0).Rows(cue2 - 1)
End If
Dim data() = {cuedata1, cuedata2}
For i = 0 To 1
If cues(i) <> -1 Then
snd_delay(i) = data(i).Item("Delay")
snd_startvol(i) = safeNum(data(i).Item("Start_Vol."))
snd_file(i) = data(i).Item("File")
snd_in(i) = data(i).Item("Fade_In")
snd_out(i) = data(i).Item("Fade_Out")
snd_vol(i) = safeNum(data(i).Item("Vol."))
snd_hold(i) = data(i).Item("Hold")
snd_af(i) = If(data(i).Item("AF") = "", False, True)
player_list(i).URL = snd_file(i)
snd_current(i) = snd_startvol(i)
If snd_startvol(i) <> snd_vol(i) Then 'snd_startvol(i) and snd_vol(i) were the same in all my tests, so this should not run.
snd_next(i) = snd_vol(i)
Dim num_steps_up = snd_in(i) * snd_speed
Dim num_steps_down = snd_out(i) * snd_speed
Dim diff = snd_vol(i) - snd_startvol(i)
Dim small_step As Single
If diff > 0 Then
small_step = diff / num_steps_up
ElseIf diff < 0 Then
small_step = diff / num_steps_down
End If
snd_steps(i) = small_step
timer_snd_fade.Tag = 0
timer_snd_fade.Enabled = True
End If
timer_snd_master.Tag = 0 'resets the tag to 0
timer_snd_master.Enabled = True 'Starts timer
End If
Next
End Sub
Private Sub timer_snd_master_Tick(sender As Object, e As EventArgs) Handles timer_snd_master.Tick
If sender.Tag = snd_delay(0) Then
Player1.Ctlcontrols.play() 'This is the only play command in the program
Debug.Print("tag " & sender.Tag) 'These print after the delay
Debug.Print("delay " & snd_delay(0))
End If
sender.Tag += 1
End Sub
Inspect the:
AxWindowsMediaPlayer player1 = ...; // get the player from UI
IWMPSettings sett = player.settings;
sett.autoStart == ??
see the docs.
Probably it is set to true, as it's default value. Simply set it to false it the player will not play until Ctlcontrols.play() is invoked.

How to search in listview

I am trying to create a Loop that will read through the information on my ListView through the SubItem to find the text that matches the text in my Textbox whenever I hit the search button and Focuses the listbox onto the matched text. Below is what I have but it keeps telling me that the value of string cannot be converted. I am also pretty sure that my numbers wont loop correctly but I am not really sure how to cause them to loop endlessly till end of statement.
Dim T As String
T = Lines.Text
For r As Integer = 0 to -1
For C As Integer = 0 to -1
If List.Items(r).SubItems(C).Text = Lines.Text Then
List.FocusedItem = T
End If
Next
Next
End Sub
I don't understand your code, but I do understand the question. Below is example code to search all rows and columns of a listview. Search is case insensitive and supports a "find next match" scenario. If a match or partial match is found in any column the row is selected. TextBox1 gets the text to find. FindBtn starts a new search.
Private SrchParameter As String = ""
Private NxtStrtRow As Integer = 0
Private Sub FindBtn_Click(sender As Object, e As EventArgs) Handles FindBtn.Click
If Not String.IsNullOrWhiteSpace(TextBox1.Text) Then
SrchParameter = TextBox1.Text
NxtStrtRow = 0
SearchListView()
End If
End Sub
Private Sub ListView1_KeyDown(sender As Object, e As KeyEventArgs) Handles ListView1.KeyDown
If e.KeyCode = Keys.F3 Then
SearchListView()
End If
End Sub
Private Sub SearchListView()
' selects the row containing data matching the text parameter
' sets NxtStrtRow (a form level variable) value for a "find next match" scenario (press F3 key)
If ListView1.Items.Count > 0 Then
If SrchParameter <> "" Then
Dim thisRow As Integer = -1
For x As Integer = NxtStrtRow To ListView1.Items.Count - 1 ' each row
For y As Integer = 0 To ListView1.Columns.Count - 1 ' each column
If InStr(1, ListView1.Items(x).SubItems(y).Text.ToLower, SrchParameter.ToLower) > 0 Then
thisRow = x
NxtStrtRow = x + 1
Exit For
End If
Next
If thisRow > -1 Then Exit For
Next
If thisRow = -1 Then
MsgBox("Not found.")
NxtStrtRow = 0
TextBox1.SelectAll()
TextBox1.Select()
Else
' select the row, ensure its visible and set focus into the listview
ListView1.Items(thisRow).Selected = True
ListView1.Items(thisRow).EnsureVisible()
ListView1.Select()
End If
End If
End If
End Sub
Instead of looping like that through the ListView, try using a For Each instead:
searchstring as String = "test1b"
ListView1.SelectedIndices.Clear()
For Each lvi As ListViewItem In ListView1.Items
For Each lvisub As ListViewItem.ListViewSubItem In lvi.SubItems
If lvisub.Text = searchstring Then
ListView1.SelectedIndices.Add(lvi.Index)
Exit For
End If
Next
Next
ListView1.Focus()
This will select every item which has a text match in a subitem.
Don't put this code in a form load handler, it won't give the focus to the listview and the selected items won't show. Use a Button click handler instead.
This is the easiest way to search in listview and combobox controls in vb net
dim i as integer = cb_name.findstring(tb_name.text) 'findstring will return index
if i = -1 then
msgbox("Not found")
else
msgbox("Item found")
end if