Open form with Combo box item picked (1 Viewer)

RJW

Registered User.
Local time
Today, 18:28
Joined
Sep 21, 2006
Messages
44
I have a database for my company's printers. On the Main menu is a button that opens the CartridgeUse form. On this form is a combo box that allows me to pick a specific printer, which populates various fields about that printer and I then enter the number pages printed, click save and it closes the form. The Main menu also has buttons for each printer. Clicking one of these buttons opens the PrinterData form and shows information (purchase date, repairs, ...) about that printer. On this PrinterData form is a "New Cartridge" button that opens the same CartridgeUse form. When I go to the CartriadgeUse form from the PrinterData form, I want it to automatically pick that printer form the Combo box, which then would populate the various fields.

I've tried a few things like this without success

Private Sub Form_Load()

If Forms!PrinterData!Text12 = 1 Then
Forms!CartridgeUse!Combo76.Column(0) = 1
end if

Can someone steer me in the right direction?

Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:28
Joined
Oct 29, 2018
Messages
18,962
Hi. Have you tried using the WhereCondition argument of the OpenForm method?
 
  • Like
Reactions: RJW

June7

AWF VIP
Local time
Today, 14:28
Joined
Mar 9, 2014
Messages
4,374
Really should give controls more meaningful names than the defaults assigned by Access. What is Text12 for?

Use OpenArgs of OpenForm to pass printer ID to CartridgeUse form. Is form opened to new record row? Then code in Open event;

If Not IsNull(Me.OpenArgs) Then
Me.Combo76 = Me.OpenArgs
End If

Is Combo76 bound to field?

Are you duplicating printer info into CartridgeUse table? Should just save PrinterID, not all associated info about printer.
 
  • Like
Reactions: RJW

RJW

Registered User.
Local time
Today, 18:28
Joined
Sep 21, 2006
Messages
44
Really should give controls more meaningful names than the defaults assigned by Access. What is Text12 for?

Use OpenArgs of OpenForm to pass printer ID to CartridgeUse form. Is form opened to new record row? Then code in Open event;

If Not IsNull(Me.OpenArgs) Then
Me.Combo76 = Me.OpenArgs
End If

Is Combo76 bound to field?

Are you duplicating printer info into CartridgeUse table? Should just save PrinterID, not all associated info about printer.
When the PrinterData form loads Text12 holds the printerID number

I've never used OpenArgs before, so I'll have to do some googling.

CartridgeUse form does not open to new record.

Combo76 is bound to the ID field of a query that lists active printers.

Sorry, but I can't answer the duplicating printer info question. I'm not sure what you're asking? There are some repeat information on the two forms, but all I'm passing to CartridgeUse from PrinterData is the ID number. Each form displays printer information from various queries based on the ID.

I'm sorry I can't answer any better, I'm self taught with Access.

I do appreciate everyone giving their time and talents to help me.
 

June7

AWF VIP
Local time
Today, 14:28
Joined
Mar 9, 2014
Messages
4,374
If you want to provide db for analysis, follow instructions at bottom of my post.

If you want to create a new CartridgeUse record then form probably needs to be on new record row.
 
  • Like
Reactions: RJW

RJW

Registered User.
Local time
Today, 18:28
Joined
Sep 21, 2006
Messages
44
I'm real apprehensive about uploading the database because it's going to show so many things I'm doing incorrectly or inefficient. Just remember, I'm self taught with lots of code copied off the internet. The reason this question came up is because I was giving the UI an upgrade or facelift. The current PrinterData form is the old style.

Thanks for everyone's help.
 

Attachments

  • printers.zip
    1.6 MB · Views: 155

theDBguy

I’m here to help
Staff member
Local time
Today, 15:28
Joined
Oct 29, 2018
Messages
18,962
I'm real apprehensive about uploading the database because it's going to show so many things I'm doing incorrectly or inefficient. Just remember, I'm self taught with lots of code copied off the internet. The reason this question came up is because I was giving the UI an upgrade or facelift. The current PrinterData form is the old style.

Thanks for everyone's help.
Give this a try...
 

Attachments

  • Printers (2).zip
    1.5 MB · Views: 173
  • Like
Reactions: RJW

theDBguy

I’m here to help
Staff member
Local time
Today, 15:28
Joined
Oct 29, 2018
Messages
18,962
Thanks. It works great. Now, I'll look through the code and see if I can learn something.
Let us know if you have any question. Good luck!
 

Users who are viewing this thread

Top Bottom