New Records on Dialog Box (1 Viewer)

fedebrin

Registered User.
Local time
Yesterday, 17:07
Joined
Sep 20, 2017
Messages
59
Hello,

I created a form with vendors which has a button and opens up another form in "dialog ratesheet" format with that vendor's contacts.

The button worked well in that it filters the form with the appropiate VendorID but when I need to enter a new contact, I have to manually enter the VendorID every time.

How can it default to the same VendorID?

I found that this works automatically for Sub Forms but when another form is opened with a button it carries the filter to see only the appropiate Vendor's contact but not the default VendorID

Thanks for your help!
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:07
Joined
Oct 29, 2018
Messages
21,453
Hi. You can assign the default value using code when you open the form. For example, you could pass the VendorID using the OpenArgs parameter and then in the Open event, you could try something like:


Code:
Me.VendorID.DefaultValue=Me.OpenArgs
 

fedebrin

Registered User.
Local time
Yesterday, 17:07
Joined
Sep 20, 2017
Messages
59
Thanks... I go this far with some VBA (I found this one on the FormsDemo):

Dialog window opens but it is not filtered at all with the correct Vendor


Private Sub Command78_Click()

Const FORMNAME = "Sub_CONTACTS"
Const MESSAGETEXT = "No record."
Dim strCriteria As String

strCriteria = "VendorID = " & Me.VendorID


If Not IsNull(Me.VendorID) Then

Me.Dirty = False

DoCmd.OpenForm "Sub_CONTACTS", _
WhereCondition:=strCriteria, _
WindowMode:=acDialog, _
OpenArgs:=(Me.VendorID)
Else
MsgBox MESSAGETEXT, vbExclamation, "Invalid Operation"
End If

End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:07
Joined
Oct 29, 2018
Messages
21,453
Hi. Is the current VendorID value already exists in FormB? I thought you said the button is used to create new records?
 

fedebrin

Registered User.
Local time
Yesterday, 17:07
Joined
Sep 20, 2017
Messages
59
Yes, the VendorID already exists in the DataBase.

We are adding contacts to that vendor which are linked to the vendor by the same VendorID field
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:07
Joined
Oct 29, 2018
Messages
21,453
Not sure if we're on the same page yet but try adding the code I suggested earlier in Open event of the opening form.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:07
Joined
Oct 29, 2018
Messages
21,453
No, it is not working, sorry
Would you be able to post a sample db with test data? I’m not sure I am following without seeing what you’re doing or dealing with.
 

fedebrin

Registered User.
Local time
Yesterday, 17:07
Joined
Sep 20, 2017
Messages
59
Sure, sorry about not being clear:

In the DB there are 2 Tables:

1) Vendors
2) Contacts

Both of them have the field VendorID which links them (1 vendor will have many contacts within their organization - one to many relationship - see capture)

Now on the main form for vendors, instead of having a sub_form, I would like for the form "contacts" to open up in dialog mode displaying the contacts for that specific vendor, I managed to do this however when I am to enter a new record on the "contacts" form, the new record does not have by default the VendorID, it obliges me to enter it manually.

Thanks again!
 

Attachments

  • Capture.JPG
    Capture.JPG
    29.2 KB · Views: 52

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:07
Joined
Oct 29, 2018
Messages
21,453
Hi. Thanks for posting an image of your table relationship but it doesn't help me much to help you since you're trying to fix your form - not your table. I'll need to see how you applied the code I suggested. For example, if you're opening the second form to add a new record, then filtering it to a VendorID may not work if the child table doesn't have a matching record yet.
 

fedebrin

Registered User.
Local time
Yesterday, 17:07
Joined
Sep 20, 2017
Messages
59
Hello,

When the second form is opened to enter the record of a new contact, the VendorID is not defaulted. I have to manually enter it.

The contact form opens and all the contacts are properly filtered though to the corresponding VendorID.

Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:07
Joined
Oct 29, 2018
Messages
21,453
Hello,

When the second form is opened to enter the record of a new contact, the VendorID is not defaulted. I have to manually enter it.

The contact form opens and all the contacts are properly filtered though to the corresponding VendorID.

Thanks
Like I said earlier, you can use code to set the Default Value for VendorID by using code similar to what I posted before. If you can post a copy of your database, we can see where you put it or fix it if it's not working.
 

fedebrin

Registered User.
Local time
Yesterday, 17:07
Joined
Sep 20, 2017
Messages
59
Good morning,

see if you can see the attached Database. I simplified it for this purpose.

Thanks for all your help!
 

Attachments

  • Vendors and vendor contacts.accdb
    512 KB · Views: 41

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:07
Joined
Oct 29, 2018
Messages
21,453
Hi. Thanks. Check out the attached modified version of your file.
 

Attachments

  • Vendors and vendor contacts.accdb
    488 KB · Views: 36

fedebrin

Registered User.
Local time
Yesterday, 17:07
Joined
Sep 20, 2017
Messages
59
Excellent! that code looks very simple and it works!

thanks so much
 

fedebrin

Registered User.
Local time
Yesterday, 17:07
Joined
Sep 20, 2017
Messages
59
Oh, one more thing... I realized the VendorID is actually a text value, not a number... how would that code change?

See attached revised database

Thanks!
 

Attachments

  • Vendors and vendor contacts.accdb
    512 KB · Views: 40

fedebrin

Registered User.
Local time
Yesterday, 17:07
Joined
Sep 20, 2017
Messages
59
could you do the same VBA code but for a VendorID that is text (not number format)

thanks!
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:07
Joined
Oct 29, 2018
Messages
21,453
Yes. You could try something like:


Code:
Me.VendorID.DefaultValue = """" & Me.OpenArgs & """"
 
Last edited:

fedebrin

Registered User.
Local time
Yesterday, 17:07
Joined
Sep 20, 2017
Messages
59
I tried it as follows and the default VendorID appears but it is not filtering it correctly... see attachment

Code:
DoCmd.OpenForm "VendorContacts", acFormDS, , Me.VendorID.DefaultValue = """" & Me.OpenArgs & """", acFormEdit, acWindowNormal, Me.VendorID
 

Attachments

  • Vendors and vendor contacts.accdb
    800 KB · Views: 38

Users who are viewing this thread

Top Bottom