Linking drop down menu to a new form in MS Access - ms-access

I created a drop-down menu with 3 selections. I need to link each selection to open up a new form so that the user will have choices for each selection. Any help would be greatly appreciated!

You've got quite a short vague question there, in this answer I'm assuming that by "drop-down menu" you mean combo box.
On the "Change" event for your combo box, have a select case statement that has case statements corresponding to each value that your combo box could take. For each case statement have a DoCmd.OpenForm("FormName".....) statement for each form you would like to open.
If you want a more specific answer, please post a more specific/detailed question (with code you've tried).

If the selections in your combo box contain the actual form names you want to open, you can do this with a single statement in the combo box's "On Change" or "After Update" event:
DoCmd.OpenForm Combo1.Value
If the values in your combo box will be different than the form names you want to open, you can write a select statement:
Select Case Combo1.Value
Case "Option1"
DoCmd.OpenForm "Form 1 Name"
Case "Option2"
DoCmd.OpenForm "Form 2 Name"
Case "Option3"
DoCmd.OpenForm "Form 3 Name"
End Select

Related

Grab and return Item from one form to other in Access VBA

Since it's the first time I do this, I want to know the best approach or right way to get the result.
I have a form (Quote) where I have a List Box to add items. I also have another form (Search Item) where I can find all the items in my database. Where I want to do is to grab an item from the Search Item box and put it in my Quote Form List Box.
I was thinking to put a Global Variable that will store the ID of the item and use this as pin point reference to paste in the Quote List Box.
Is this the right way to it or am I missing something here?
To reference the form you're currently on:
Me
To reference a textbox control in the form you're currently on:
Me.txtbox_name_here
To reference a form from another form:
Dim frm As Form
'first you need to open the form to reference it
DoCmd.OpenForm "form name here", acNormal
'references the form the form
Set frm = Forms("form name here")
'when you're done remember to close the form with this
DoCmd.Close acForm, "form name here", acSaveYes
To reference another form's textbox control, using the frm variable I made earlier:
frm.txtbox_name_here
This should be enough information for you to get started.

Pop up a form when a specific field value is choosen in the combobox in Access 2007

I have a combo box in the "Form A" where field values are poupulated from another table in Access 2007. "Form A" is of datasheet type and there are 3 hidden columns. I try to make a Pop-up form("Form B") that will open up when a specific value(e.g. "RAIL") is selected in the combobox and use "Form B" to fill the hidden columns values.
I try:
Private Sub Combo36_Change()
If Combo36.Value = "RAIL" Then
DoCmd.OpenForm FormName:="Received"
End If
End Sub
But that doesn't work. Any help is appriciated. Thanks in advance.

Access 2007 textbox is seen as empty while it is not

I was searching for my question for hours and I have found some ideas but it still doesn't do what I want.
I have a form "AddWorker" with texboxes "Name", "Surname" and so on.
At the end of this form I decided to use a button to handle addition to database by VBA code.
When I put some data into texboxes I can refer to them by textbox.text property, but only if I am focused on this texbox. In other cases I can use textbox.value property.
In my case when I put all data into 3 textboxes I clik button "Add worker" to add person to database, but last textbox (for example 3) is seen as empty because it did't see text I have put into textbox. I need to clik into another textbox (for example 2 or 1) to create "some event" and then it update textbox 3 and all data can be read in vBA.
What can I do to see all texboxes filled in VBA when i click "Add worker" button.
I have found some example but it didn't help me a lot. I still see empty textbox while clicking "Add worker" button.
Textbox null problem
First of all, make sure the form is unbound. It should not have a recordsource associated with it.
Then, try adding a few messageboxes in the code behind the Add Worker button. Something like:
Sub Add_Worker_Click()
msgbox "Text1: " & Me.TextBox1.Value
msgbox "Text2: " & Me.TextBox2.Value
msgbox "Text3: " & Me.TextBox3.Value
/* Comment out all of your code for now */
End Sub
Give that a shot and see what is in the textboxes. Then replace ".Value" with ".Text" and see what you get.

Update/Requery textbox after cascading combo box

I have a form with two dependent cascading combo boxes with a textbox. What I want it to do is after I select the 2nd combo boxes (cboxHDD), the txtDescription would update or requery to the selection of cboxHDD. I found some examples online but I can't seem to get it to work update/requery.
The code to txtDescription:
With Me
.txtDescription.Value = cboxHDD.Column(3)
End With
The database is also provided in the following link:
Computer-HDD Database
Have you tried putting txtDescription.Value = cboxHDD.Column(3) in the "After Update" event of cboxHDD?

MS Access de-select listbox after running macro/query

So I have a form (frmBookingForm) in Access, and a listbox (lstMyBookings) that displays the results of a query.
Below this, I have a button (cmdDeleteBooking) which runs a delete query using the lstMyBookings selection as input. The button then runs a macro that firstly checks whether a record in the listbox is selected, and if one is, runs the delete query and requeries the data, so the deleted record is no longer shown in the listbox. If not, an error message is displayed.
However, if I then click the button again, it again runs the delete query, even though there is apparently nothing selected in the list box.
Essentially, how can I 'clear' the listbox selection?
I'd prefer a solution that can be done in a macro format, as I have little to no understanding of VBA. However, if providing a VBA solution, I'd greatly appreciate a short explanation of it.
Thanks :)
Looks like this website has a nice little function to do it. Essentially, you need to test if it's a multiselect, and then do one of two things. I suppose if you know ahead of time that it is/isn't a multiselect, you wouldn't even need the "if" statement:
If List0.MultiSelect = 0 Then
List0 = Null
Else
For Each varItem In List0.ItemsSelected
List0.Selected(varItem) = False
Next
End If
If the control's MultiSelect property is set to None, this code just sets List0 to Null. If the control's MultiSelect property is set to anything else, the code loops through all items that are currently selected, and sets the Selected property of that item to False. My example assumes your control is called List0.
EDIT
To use this code, use an event instead of a macro. Here's how you do this:
Right click on the button, select properties
In the Property Sheet window, click on the "Event" tab
Click inside of the "On Click" blank area, and click the dropdown arrow, then select "[Event Procedure]"
Click the ellipsis ("...") to go into the code editor.
In the code editor, your should already have your event for the button (let's assume the button is called Command1:
Private Sub Command1_Click()
End Sub
Add your code in between (assuming the listbox is called List0):
Private Sub Command1_Click()
If List0.MultiSelect = 0 Then
List0 = Null
Else
For Each varItem In List0.ItemsSelected
List0.Selected(varItem) = False
Next
End If
End Sub