Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Combo Box to open Form? 3

Status
Not open for further replies.

jmbcreative

Technical User
Jan 30, 2006
58
US
I have a form that has a combo box in it with values that I manually inputed. One of those values is "add hardware". I need the HardwareAdd form to open up when the "add hardware " value is selected. How can I do that?
 
Assuming that the other values are other forms in your database then
put this code in the after update property of your combo box
'~~~~code begins

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = Me.YourComboBox
DoCmd.OpenForm stDocName, , , stLinkCriteria

'~~~~code ends

Hope this helps

Jimmy
 
Thanks Jimmy,

That code may prove to be usefull further into my development, but for now I need to be more specific. Not all the values in the combo box need to open forms only specific ones. How can I do that?

I found this code while searching and attempted to use as an afterupdate proceedure, but it is not working. Any ideas?

****code***

If Me.Combo63 = "Add Hardware" Then
DoCmd.OpenForm "Form_HardwareAdd"
End If

***code***
 
You may check the name of your form, and put it exactly as shown. The Form_ is not needed for DoCmd.OpenForm unless thats what you named it. I know VB adds this prefix when using it as a variable name as opposed to the form name.

you may try
Code:
Private Sub Combo63_Change()
    If Combo63.Value = "Add Hardware" Then
        DoCmd.OpenForm "HardwareAdd"
    EndIf
End Sub

-Pete
 
You get a giant pink star for that. Many Thanks Pete!

-Joe
 
Now that I have the HardwareAdd form open I need to do one last thing, that will most likely be a little complicated.

I have a control button at the bottom of the Hardware Add form that simply goes to a new record saving the data that was just inputed. I need that control button to also insert the control Id (that is the primary key of the Hardware Add table) into a field(SystemDiscription) of the open record of the other open form, preferably as a link.(which is the real complicated part).

Any takers on this solution?
 
Im trying to better understand this:

You want to have like a hyperlink on the newly opened HardwareAdd form that will automatically put the newly made primary key into the field SystemDiscription of the form that originally launched HardwareAdd?

If thats the case...
1) what is the name of the original form?
2) what is the control name on HardwareAdd that stores the control id?
3) what is the control name on the Original form that you want this control id to be inserted?

This wont be too complicated. =]

-Pete
 
Going a bit futher if the other vavuel in you combo have to be used then you may wish to use a select case statement

'======Code Begins
Select Case Me.Combo63

Case "Add Hardware"

DoCmd.OpenForm "HardwareAdd"
Case "Your next Case"

' your action goes here

End Select

'====== Code Ends

You can put as many case statements in as you require

Jimmy


 
Thanks Jimmy. I'll add this one to my arsenal.

Pete: That is exactly right!
To answer your questions:

1) The Name of the original form is "ChangeEntry"
2) The control name on "HardwareAdd" that stores the control id is "ControlID"
3) The control name on the Original form that I want this control id to be inserted is "Discription".

 
This is where you would use the Form_. You can make the "hyperlink" on the HardwareAdd form by making a label with blue underlined text. I have a snippet of code that will change the mouse to the hand when you hover over the label if you also want it to do that. On the click event of the label you just made put code to update ChangeEntry.

Form_ChangeEntry.Discription.Value = Me.ControlID.Value

I would also like to point out that its usually spelled "Description" =] But i wouldnt worry about that now.

-Pete
 
Thanks Pete. Thanks for catching the typo. Made the changes. Not at all as dificult as I thought.

Thanks mate.

 
np

I know you didnt ask for it...but i thought id post this anyway. This will make the mouse turn to a hand:

Create a module and name it whatever you want. Then insert the following code:
Code:
Public Const IDC_HAND = 32649&
Public Const IDC_ARROW = 32512&

Public Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
Public Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long

Public Sub MouseToHand()
    Dim hCur As Long

    hCur = LoadCursor(0, IDC_HAND)
    If (hCur > 0) Then
        SetCursor hCur
    End If
End Sub
And on the label's "MouseMove" and "MouseDown" events add the line
Code:
Call MouseToHand

Hope this is useful to someone.

-Pete
 
I'll try that one. That should be usefull and pretty cool.

Two problems I'm having with the controlID code.

[1] I need the text(controlID)that was inserted into the Description field to hyperlink to the HardwareADD record.
[2] I need to add multiple controlID's into the description field. Right now it just replaces the data that is there.

-Joe
 
1) If you're going to want the click event to take you somewhere on HardwareAdd, you won't be able to use a textbox with multiple values. What I'm trying to say is i dont know of a way for access to know WHERE in the textbox you clicked...just that you clicked it.
I'm sure you could go the complicated way and make the click spawn a completely new form that has the various values from the textbox listed in a combo box or list box and ask which one to go to.

2) To make it add them side by side in the text box replace

Form_ChangeEntry.Discription.Value = Me.ControlID.Value

with

Form_ChangeEntry.Discription.Value = Form_ChangeEntry.Discription.Value & ", " & Me.ControlID.Value


-Pete
 
Thanks Pete.

Yeah I thought that would be a bit too complicated. I'll find a way around it. There is most likely a simpler way to accomplish what I need.

Many thanks for your support amigo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top