I want the 32 radiobuttons individually be able to be linked to a database when I click the 1 button which says "Submit". Meaning when I select 1 radio button and i click the submit button I would like to have a msg saying booking confirmed or something and when i click the submit button it stores it in the database. I have tried to develop something similar to this I tried making normal textboxs being able to store it in a database. How do I link MS Access to Visual Basic in order for the radio buttons to work? Would the Primary Key be the Field called Seats if thats where I want to store the data from that field in the table?
The Form comprises of:
PictureBox - which is an image that is a layout seating plan on a plane.
32 RadioButtons
1 Radio Button = 1 seat ideally
1 Button - When the user has chosen a seat they want they should click a button called "Submit". When the button is clicked I want the seat that the user has clicked on be able to be stored into a table within a database. Once the seat has been stored the next user after the previous one isn't allowed to select that particular seat that someone else has picked. I want this to be a looping process for 32 seats on the airplane until the plane is full.
Would I use a While loop for this to work or would I use an If statement and keep on saying ElseIF in my code?
Any Ideas?
for all radio buttons set seat number as text and then assign the same event handler for CheckedChanged event of all radio buttons and write the following code within that event handler.
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, ...
Dim RB As RadioButton = sender
If RB.Checked Then
'write the code to save the seat number i.e. RB.Text to database
End If
End Sub
Related
I'm creating a form in MS Access with 10 butons simulatin a numeric keypad (only the values 0..9).
I would like to change the value of a combobox control in a subform each time I click on one of these butons. The combo box control is named "projectID"
I tried this but it is not the same as pressing the same key on a keypad.
Private Sub Buton3_Click()
Call Me.frmServDedicacion_Subformulario.Form.projectID_KeyPress(51) 'Ansii code for 3
end sub
I put this procedure as keypress event in order to verifiy the combobox method is executed, and it does (msgbox is ok) but the combobox doesn't receive the KeyAscii value.
Public Sub projectID_KeyPress(KeyAscii As Integer)
MsgBox Chr(KeyAscii)
End Sub
This looks like a problem referring to a control on a sub form from the main form. I still have trouble getting this right so I use a cheat sheet:
http://access.mvps.org/access/forms/frm0031.htm
I created a main form called main and put 10 buttons named button0 - button9 on the form and I dragged a form called mysubform onto the main form to create a subform. mysubform has a textbox named projectID. Then just set the click event to button0 to:
Private Sub button0_Click()
Me!mysubform.Form!projectID = 0
End Sub
Don't forget similar click events for buttons 1-9
some things that may be helpful:
! is the bang operator see:
Bang Notation and Dot Notation in VBA and MS-Access
by default, when you drag a form to create a subform control on another form, access gives the subform control the same name as the dragged form. so here mysubform refers to the subform control and not the original form used to make the subform.
Then .Form gets the form wrapped by the subform control.
I hope this answers your question
I have a feeling this is a very simple thing that I'm overlooking.
I have two ComboBoxes that allow users to search for/select the record that they want to view. One is filled with Customer Names and the other is filled with Customer Numbers, so the user can look for a particular record by either selecting the Name or Number.
Each ComboBox is filled by a Data Table returned from a SQL Server database.
Each ComboBox has DropDownStyle set to DropDown, AutoCompleteMode set to SuggestAppend and AutoCompleteSource set to ListItems.
The user can either select by clicking the DropDown arrow and then clicking on the item they was or they can begin by typing and the ComboBox narrows the number of items in the list based on the characters the user is typing.
Using the mouse to click on the item in the list that they want works fine...it fires off a routine to retrieve the selected item from the database.
However, when the user types in the desired selection and presses ENTER, nothing happens. They must click the DropDown arrow and click on the item in order for the program to pull the appropriate record.
How do I get the ComboBox to pull the appropriate record when the user hits enter?
I'm using Visual Basic.
From the sounds of it, you need three events.
You need to use a timer to know when the user has stopped typing. To do that, you need one event would be when that field they're typing in has it's value change (<control's name>.TextChanged). That would start/restart a timer ticking (so that the user has a couple seconds to pause before the next event fires).
The next event would be the Tick event for that timer. That event would stop the timer, and then give focus to the right field so that when the user hits ENTER, they're not hitting ENTER in the field they've been typing in. You'll need to write a function to look up the right item in the ComboBox and call that.
Then you'd have a third event, either KeyPress, KeyDown, or KeyUp on the ComboBox itself. I'd lean towards the KeyUp to avoid issues if the user holds ENTER for whatever reason. That'd be what selects the item.
As a final FYI, I'm assuming you're using Visual Studio to write your code. If not, you should, and if you are/once you are, you can select the field you want to work with in the drop-down at the top left of the editor and then look at the associated events in the top right drop-down.
Thank you to JMichael for getting me on the right track with this one. I'm posting my solution here just in case it helps someone who has a similar question in the future:
The code that I added to the ComboBox's SelectionChangeCommitted event needed also to be added to the ComboBox's KeyUp event:
Private Sub cboPolicySearch_KeyUp(sended as Object, e As KeyEventArgs) Handles cboPolicySearch.KeyUp
If e.KeyCode = Keys.Enter Then
GetSelectedPolicySearchRecord()
e.Handled = True
End If
End Sub 'cboPolicySearch_KeyUp
The GetSelectedPolicySearchRecord() sub contained all of the information I needed to call my SQL Stored Procedure to select the data for the record that the user selected in the ComboBox.
Previously, this was only being called from the ComboBox's "SelectionChangeCommitted" event which is executed when the user clicks the drop down and then clicks a policy number from the drop down list.
I needed to add the same call to the GetSelectedPolicySearchRecord in the ComboBox's "KeyUp" event for when the user presses enter.
I'm working on a windows form app containing a TabControl. In one of the TabPages I have a GroupBox that contains a FlowLayoutPanel. I also have a SQL database table containing user notes/comments. Upon form load, I use a SqlDataReader to populate a user control for each note (creation date, note text, username, etc.). The FlowLayoutPanel then gets filled by UserControls. However, I would like for the user to be able to select individual notes/UserControls for editing/deleting. I was initially using a DataGridView instead of UserControls, but notes vary in length and the DataGridView didn't look very organized. My UserControl contains a self-expanding RichTextBox. I thought about adding CheckBoxes next to each UserControl, but I'm not sure how to track which box belongs to which UserControl. Is there a smarter way to accomplish this?
This is a url for a screenshot of the UserControl: https://imgur.com/a/ZN7MM
(I don't have enough reputation to post images.)
And here is the code I got from another post on the self-expanding richtextbox:
Private Sub RichTextBox1_ContentsResized(sender As Object, e As ContentsResizedEventArgs) Handles rtbNote.ContentsResized
rtbNote.Height = e.NewRectangle.Height + 10
End Sub
at first i am sorry for my weak english but i will try my best to explain my issue
i am new in programming so i got idea but i don't know if can be happen or not
the idea is , i have 2 form separated each form have there cods , but i want to add button in form one its open the second form, to add thing to the second one , but i need to return to first form when i close the second form
can i do something like that ??
for clarification the second form i can open it from other ways and have own function and the first form too
UPDATING !!!
at first thank for all your answers and not useful vote ,second yes i am new but not that much i know how to use formname.show() and formname.close() etc..... ,the issue not about usual ways to open and close forms, for example in form one i input information about user one of the option is where he live, the country choosing from dropbox ,next to the dropbox there button named add new country the button open new form to add new country when i add new country and closed the form back to the first form , and just to be know there button in the third form (setting) to open the form add new country ,IN SHORT WORD I DON'T NEED TO OPEN THE FIRST FORM EVERY TIME I CLOSE THE SECOND ONE , ONLY RETURN TO THE FIRST FORM IF I CAME FROM THE BUTTON THAT I CLICKED IN FORM ONE
put this on action
formname.show() 'for opening a new form
formname.close() 'for opening closing the form
formname.showdialog() 'Where you cant click the main form``
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'show form 2
Form2.Show()
'move text from one form to another
Form2.TextBox1.Text = TextBox1.Text
End Sub
okay... How do I explain this without being totally confusing?... Alright, I have this form that has MenuScripts (top-levels and second-levels). The problem that I am having is one of the second-levels is "Add" which brings you to another form when clicked. This other form has a button ("Record") and text boxes. This other form allows the user to input data and when the record button is clicked, the inputted data is written into a text file. Ok, so back to the first form. Another second-level MenuScript is "Update" which also brings the user to the other form; but first, the user has to click an item within a listbox to proceed. How do I get the data from the selected item to appear in the appropriate textboxes and how do I get the record button to update data instead of being confused and thinking it is only a add-data button?
Is there a way to use an "if" statement to say something like "if mnuAdd is clicked then" "elseif mnuUpdate is clicked then". Would something like that work for giving the record button multiple uses?
Also, if someone can give me some pointers on making sure the user selects an item within the listbox would definitely be a plus! Thanks, guys!
Unfortunately, I cannot add images since my reputation is too low.
Here is a visual representation of my ultimate goal
Easiest way: before displaying the second form set it's Tag property to something distinct – say "Add" or "Update" – depending on which menu item is selected. Then you just test the Tag value in the button's Click event and proceed accordingly.
As for determining whether a list item is selected: well if there isn't the ListBox's SelectedIndex property will be set to -1.
You need to put a public property on the second form (Details) which specifies which mode it is in. For instance, you could create a mode enumeration like this:
Public Enum EntryModes
AddBook
UpdateBook
End Enum
Then, define a public mode property on the second form, like this:
Public Property EntryMode As EntryModes
Get
Return _entryMode
End Get
Set(ByVal value As EntryMode)
_entryMode = value
End Set
End Property
Private _entryMode As EntryMode
Then, when you show the second form from the menu, just set the property first, before showing it:
Private Sub mnuAdd_Click(sender As Object, e As EventArgs)
Dim dialog As New DetailsDialog()
dialog.EntryMode = EntryModes.AddBook
dialog.ShowDialog()
End Sub
Private Sub mnuUpdate_Click(sender As Object, e As EventArgs)
Dim dialog As New DetailsDialog()
dialog.EntryMode = EntryModes.UpdateBook
dialog.BookToUpdate = ListBox1.SelectedItem
dialog.ShowDialog()
End Sub
As you can see, in the Upate menu click, I also added a line that passes the information for which book should be updated.