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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a subform of some default values upon opening it.

Status
Not open for further replies.

sanan

Technical User
Apr 15, 2004
139
IR
Hi there
I have a subform called “Products Details”in my form called “sales” . This Subform has a DefaultView of DataSheet. This subForm has a comboBox called “ComProducts” with different Products in it;
Here is the challenge, I want upon opening the “Parent form (sales) and Consequently the Subform” 3 most used or selected products to be Selected or shown in my Subform (Off course, In 3 or 4 different rows).
Now is this possible? And if it is, how?

Best Regards
Sanan
 
Hallo,

You can use DoCmd.RunSQL to run an Action query to add records. Add 3 or 4 calls to this on your Sales OnOpen event.

Use the INSERT INTO SQL syntax to add records.

- Frink
 
HiFrink
I am sorry for delay to respond.
Your suggestion gave me an Idea, and That is That I want to Insert Directly into the Table which is the record source of my Form. And then just refresh the Form.
I think that should work, But I came up with a very Strange Problem;
The Insert routine is giving me a strange problem, Here is my code;

Private Sub SaveAccountDetails_Click()
Dim myCn As New ADODB.Connection
Dim myRs As New ADODB.Recordset
Dim R As Integer
Dim RR As Integer
R = 100
RR = 500
myCn.ConnectionString = "DSN=TT2"
myCn.Open
myRs.Open "INSERT INTO [dbo].[Account Details] (SalesID, Account#) VALUES (" & R & "," & RR & ");", myCn, adOpenDynamic
End Sub

This is just a test, It should add the values to my Table “Account details”, But it does not.
I should mention using the same technique with the same Table in this Application I had success But at the moment it is not working.
This is the code that is working;

Private Sub AccountDetailsAdd_Click()
Dim myCn As New ADODB.Connection
Dim myRs As New ADODB.Recordset
myCn.ConnectionString = "DSN=TT2"
myCn.Open
myRs.Open "INSERT INTO [dbo].[AccountDetailsFinal] SELECT * FROM [dbo].[Account Details] ;", myCn, adOpenDynamic
myRs.Open "Truncate table [account details] ;", myCn, adOpenDynamic
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
End Sub

I think the Column Name of “Account#” could cause the problem. Just a guess.
A note that the “SalesID” and “Account#” are Primary Key and cannot take a Null Value.

Best Regards
Sanan
 
Hallo,

That whole syntax looks a bit wierd, but that's probably because I'm no ADO expert, but if the second one works then I guess it must be the Account# or something similar.

Try putting Account# in square brackets, [Account#]

- Frink
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top