Code help with Forms (1 Viewer)

Weekleyba

Registered User.
Local time
Today, 16:00
Joined
Oct 10, 2013
Messages
586
Ok...I've been working on this and cannot quite get it to work.

The user can add a project by clicking the button.
There is some validation of control in the before update...works good.
The user can then select the 'Open Contract' button.
There is some validation of control in the before update...works good.

Two problems:

1. When you click the close button in F_Contract, you have to click it twice. I see why this is happening in my code but, I don't know how to fix it. I simply want to click the button once and close. How do I fix this code and still get the validation of control to work?


Code:
Private Sub ButtonClose_F_Contract_Click() On Error Resume Next If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord 'This trys to save but the BeforeUpdate event fires which has the Public Function in it. Else DoCmd.Close End IfEnd Sub
2. When the F_Contract is closed, I cannot get the combo box, cboContract to land on the TEMP contract number that was generated in F_Contract.
If I choose …..listcount -1, it gives me the next to last in the list. Which is expected. But if I choose ….listcount , (with no "- 1" at the end) then it gives me a blank. How do I correct this?


Code:
Dim LastRow As Integer LastRow = Forms!F_Project!SF_Contract!cboContract.ListCount ctlCombo.Value = Forms!F_Project!SF_Contract!cboContract.ItemData(LastRow)

See my attached sample database.
Thanks for any help.
 

Attachments

  • DB test 2.zip
    53.5 KB · Views: 291

theDBguy

I’m here to help
Staff member
Local time
Today, 14:00
Joined
Oct 29, 2018
Messages
21,358
Hi. See if this does what you need.
 

Attachments

  • DB test 2.zip
    45.3 KB · Views: 342

Weekleyba

Registered User.
Local time
Today, 16:00
Joined
Oct 10, 2013
Messages
586
I'm getting super frustrated with this!
I thought I had it working....and your change is good but, now I can't figure out what is wrong.

Can you PLEASE take another look at this?

Problems:
1. Add new project, click on 'Open Contract'. Contract opens with TEMP number. All good. Now close it and it still will not show the TEMP number in Combo without dropping down to select it. I'm trying to have the contract number in the combo already loaded and generate the record in the SF_Contract.

2. Another problem is, when in the F_Project with a Contract number in the SF_Contract and you click the 'Open Project' is does not go to that specific Contract. Maybe I've been at this to long today.....

Can you help me understand what I am doing wrong?
 

Attachments

  • DB test 2DBguy1.zip
    43.2 KB · Views: 336

theDBguy

I’m here to help
Staff member
Local time
Today, 14:00
Joined
Oct 29, 2018
Messages
21,358
I'm getting super frustrated with this!
I thought I had it working....and your change is good but, now I can't figure out what is wrong.

Can you PLEASE take another look at this?

Problems:
1. Add new project, click on 'Open Contract'. Contract opens with TEMP number. All good. Now close it and it still will not show the TEMP number in Combo without dropping down to select it. I'm trying to have the contract number in the combo already loaded and generate the record in the SF_Contract.

2. Another problem is, when in the F_Project with a Contract number in the SF_Contract and you click the 'Open Project' is does not go to that specific Contract. Maybe I've been at this to long today.....

Can you help me understand what I am doing wrong?
Hi. For Problem #1, I must be missing a step. Here's what I did:

  1. I opened your database and the F_Project form automatically opens up
  2. I click on the Add New Project button and the form goes to a blank record
  3. I enter a Project Name and select an engineer from the dropdown
  4. I click on the Open Project button and get an error
What step am I missing?
 

Weekleyba

Registered User.
Local time
Today, 16:00
Joined
Oct 10, 2013
Messages
586
Maybe this little database is corrupted some how.??
I'll start from scratch and see if that works.
If not I'll post it again.
 

isladogs

MVP / VIP
Local time
Today, 21:00
Joined
Jan 14, 2017
Messages
18,186
I haven't been following the previous thread but I've got past that issue.
However you'll still have issues on the subsequent form.
I think it needs a redesign but as I'm not sure what you're trying to do. I'll leave others to advise
 

Attachments

  • DB test _CR.zip
    75.3 KB · Views: 331

Weekleyba

Registered User.
Local time
Today, 16:00
Joined
Oct 10, 2013
Messages
586
So I've been working on this problem, this weekend and I think I have it.
Can anyone take a look at the attached sample database and let me know if this is:
a. A good approach
b. Correct coding

Any other comments welcomed too.
Thanks!
 

Attachments

  • DB Test 4.zip
    51.1 KB · Views: 324

Users who are viewing this thread

Top Bottom