Hi, Skot
Where would the information come from to fill in those fields? They don't
sound like something that should be in another table for you to 'copy and
paste' across with an append query
I thought that they would be something on page 2 of your tab, in the
FrmJobHistory Subform
One important question.
Does your TblJobDetails have one record per job and just provides further
details about the job?
Does your TblJobHistory have several records per job
In the meantime, here is how I'm using a form with 2 subforms in tab
controls. You may be able to adapt some of the ideas eg how to go to the
last record of the second subform and how to ensure that a newly added
record is saved
The lines starting with apostrophes won't run as code - they are comments
In my case, the second subform is not linked to the main form but to the
first subform. You'll see that the tab control is actually ignored in the
code - when you set focus on the second subform this automatically 'turns
the page'
Main Form FrmSales has the fields Manufacturer and ManID (primary key of
TblManufacturer
Tab is TabSales
PgProduct has FrmSalesSub1 (which is linked to main form via ManID)
It lists the products for sale and has the fields
ProdID, Product and RRPrice (recommended price for product)
PgSale contains FrmSalesSub2 (a list of sold products including ProdID and
SalePrice)
It's child link is ProdID
MasterLink to the other subform is
[FrmSalesSub1].[Form]![ProdID]
(the syntax must be carefully observed)
I have a button on PgProduct which says Buy and lets me click on a product
and buy it
Private Sub cmbBuy_Click()
On Error GoTo Err_cmbBuy_Click
Dim stDocName As String
Dim MyProd As Long
Dim MyPrice As Double
Dim MySql As String
Dim MyMsg As String
Dim ProductName As String
If Me.FrmSalesSub1.Form.Dirty = True Then
'save record if a new product has just been added
'and writer hasn't clicked off record yet
Me.FrmSalesSub1.Form.Dirty = False
End If
Me.FrmSalesSub1.Requery
If IsNull(Me.[FrmSalesSub1].Form.[ProdID]) Then
'nothing in the subform
MsgBox "No products for this manufacturer"
Exit Sub
End If
'fill variables
ProductName = Me.Manufacturer & " " & Me.[FrmSalesSub1].Form.[Product]
MyPrice = Nz(Me.[FrmSalesSub1].Form.[RRPrice], 0)
MyProd = Me.[FrmSalesSub1].Form.[ProdID]
MySql = "INSERT INTO [TblSale] ( [ProdID], [SalePrice] )"
MySql = MySql & " SELECT " & MyProd & " AS [ProdID], " & MyPrice & " AS
[SalePrice];"
MyMsg = "Buy " & ProductName & "?"
If MsgBox(MyMsg, vbYesNo) = vbNo Then
Exit Sub
Else
DoCmd.RunSQL MySql
'After checking this works as expected
'I can delete the DoCmd
'and uncomment the line below
'CurrentDb.Execute MySql, dbFailOnError
'this won't give the 'Record about to Added' box
Me.FrmSalesSub2.Requery
'ensure newly added record will appear in subform 2
Me.FrmSalesSub2.SetFocus
'Move to second subform
Me.FrmSalesSub2.Form.RecordsetClone.MoveLast
'move to newly inserted record for editing
End If
Exit_cmbBuy_Click:
Exit Sub
Err_cmbBuy_Click:
MsgBox Err.Description
Resume Exit_cmbBuy_Click
End Sub
"Skot" <
[email protected] wrote in message
thanks evi, that looks like it makes sense to me, i'll try and key it
tonightand see how i go.
My only question, in my TblJobHistory, i have two other fields, being
say;[Subject] and [Notes].
While i'm creating the new record, i want to fill in these two fields.
Would i use the INSERT INTO command for that one as well?
Evi
Assuming Job No is a number field. In the OnClick Event of the button you
can put in the following code
Dim MySql As String
Dim MyJobNo As Long
MyJobNo = Me.[Job No]
'the line starting MySql should be one long line
MySql = "INSERT INTO TblJobHistory ( [Job No] ) SELECT" & MyJobNo & "
AS
[Job No];"
'MsgBox MySQL
'run the append query
DoCmd.RunSql "MySql
'now requery the other subform
Me.Parent.FrmJobHistory.Requery
'end of code
If the button is actually on the Main Form then this will not work.
Justchange the MyJobNoline then to
MyJobNo = Me.YourSubformName.Form.[Job No]
"Skot" <
[email protected] wrote in message
Yep... i think we're getting there. So TblJob has a main form (FrmJob),and
inside it there are two subforms, both with their own tables associated to
them. Lets call them TblJobDetails and TblJobHistory. Both of these run
subforms in the main form off tabs. So they would be FrmJobDetails and
FrmJobHistory.
Its when we click a control on FrmJobDetails that we want to add a new
record into FrmJobHistory, fill it in, and save it.
I've got to the stage where i can open a "hidden" form and start a new
record... but its the filling in part that i'm struggling with. The link
between all the forms are that the TblJob has the [Job No] field which is
the link to TblJobDetails and TblJobHistory.
:
Oh, I see. So (I hope). You have
TblJob with something like J
obNo ( Primary Key) (1 record for each job) Job
TblJobDetails (several records for each job)
JobDetailID (PK)
JobNo (foreign key, linked from TblJob)
Details about that particular job detail
So TblJobDetails is clearly a subform of TblJob
We have probably answered this before but this thread has got a bit
convoluted.On which table is the Main form based?
Ifit is based on a third table, what is the table's name, what field linksit
to TblJob?
Or is the main form an unbound form?
Evi
"Skot" <
[email protected] wrote in message
I think we're close to what we need to do, but I didn't quite
explain what i needed to do very well...
So we have two tables on seperate tab pages, both linked by a
common [Job No] foreign key.
The user will fill in the information on the first page, (Table1)
and click a button called confirm. This will save the info (got the if
Me.Dirtypart),
and then start a new record in a new table (Table2), adding,
Date,Time,Subject and Notes into that table, save that table and the user
isnone thewiser. If it helps, the Table1 is the details of a job, Table2 is
a runninglog of
everything that happens, so basically everytime someone does
somethinginTable1, we get a description of it in Table2. The user can add
theirown info into that table as well. That way I can print a report of
Table2 andit givesme a history of that job. I thank you again for your help
Evi. Please let me know if I haven'texplained myself properly.
:
If your combo box is bound then you can't set its value to null(bound
meansthat if you changed the BuilderID field in your table, your
combobox'sdisplay would automatically change from bill smith to george
brownand ifyou changed the combo so that a different name from Bill
Smithappeared then
the ID field in your table would change) That code you have used
isfor anUnbound combo. You can put an unbound combo into your form. Base
iton yourbuilders table but when it comes to the bit in the Wizard where
issays
Your tab question: It's not the controls on page 2 that you willneed tofill
in, but the table on which page 2 is based.Is Page 2 based on a different
table from Page 1?
If yes, then the basic idea is that when you have finished adding anewrecord
to Page 1 (After Insert Event), an Append Query runs whichaddssomethingto
the table on which Page 2 is built.
Presumably Page 2 is a linked table which contains a foreign keyfield
whichis the Primary field of Page 1's table.
The code in the After Insert Event would look something like this
(depending on your field and table names.
Dim MyField1 As Long
Dim MyField1Name As String
Dim MySql As String
Dim MyOtherTable As String
MyOtherTable = "The Name of your table"
MyField1Name = "TheNameOfYourNumberField"
'edit as suits
If Me.Dirty = True Then
Me.Dirty = False
'save the current record.
MyField1 = Me.TheNameOfTheLinkingField
MySql = "INSERT INTO " & MyOtherTable & " ( " & MyFieldName & " )" &
"
VALUES ( " & MyField1 & ");"
DoCmd.RunSql MySql
If the values don't show up when you tab to page 2 then useMe.Form.Requery
in the On Click event of the page.
"Skot" <
[email protected] wrote in message
Thanks again for ur response... I really appreciate it. My combo box is
actually bound (well, i think it is).. Anyway, I've had a bit of a look at
the code again and tried a fewof your suggestions. When I change the line
to; "Me.cboBuilder.Value =
Null" i get an error message; "You tried to assign the Null value to a
variable that is not
a Variant data type". I've got rid of the onLoad procedure and checked to
make sure my query matches what you wrote but it still doesn't work. I'm
not overly concerned because I realised that the only reason why I have
blank fields in the Supervisor section is just for debugging... and i can
probably just set a default value for it if it caused too much bother...
BUT... now that I've got you answering queries, I have another one for
you... I have a TAB control on a page. I want to add a control Box on say
"Page1" that will create a new record on "Page2" (subform called "Form2"),
fill in the fields and save it... without leaving "Page1".
DoCmd.GoToRecord, , acNewRec
Me.Subject = "Job confirmed"
Me.Notes = "These are notes"
.... that worked, but I don't know how to make it work if thecontrol boxis on
a different Page... and different form. Thanks again Scott.You may have got
your code here:
http://www.access-programmers.co.uk/forums/archive/index.php/t-94035.html
Is Supervisor both the name of an actual field in your form'sRecordSource
and the name of an unbound combo box? (It's usually best toavoidcalling
Controls by a field name - Access will get revenge on you!). I ask because
ItemData (number) is usually used to find aparticularitem in an unbound list
or combo box using the order that the itemappears in -the first item is
always 0, the second item in the list is always 1. The code is used so that
the user, instead of being faced with a blank unbound combo when he opens
his form, is faced with one thatalready contains the first line of data (are
you sure that you want this?)
I can't imagine what it would do if the combo box is a bound one. Is it?
I suspect strongly that there are things that you haven't told us. For
instance, are you trying to filter an unbound form? What is the purpose of
the Unbound combo? Are you actually trying to filter a form at all or are
you trying to filter a combo?
If by any chance you want to filter a combo using another combo thenthe
method is slightly different. This may give you the idea. Your first combo,
cboSupervisor has a list of Supervisors - itis basedon the TblSupervisor
table and has SupervisorId (Primary key) andSupervisorName
cboBuilder has a list of builders which that Supervisor looks after.
To get its data, you create a query based on TblBuilders table and