Sub form not displaying as continuous

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I came across a problem that I have set the sub form to addnew and continuous
form, however when entering data in the subform and reaching the last field
the next tab takes me to the beginning of the line I just typed ( I checked
the sub record and it gets written). I really want to get a new line and be
able to see all the records entered in continuous form mode. Any insights
would be greatly appreciated.
 
Not sure what you mean by "set the sub form to addnew". AddNew is a method
used by recordsets, and typically is not a property set for a subform.

Please give us more details about how you get to the subform and the code
that you're running before and after data entry.
 
FatherBob said:
I came across a problem that I have set the sub form to addnew and continuous
form, however when entering data in the subform and reaching the last field
the next tab takes me to the beginning of the line I just typed ( I checked
the sub record and it gets written). I really want to get a new line and be
able to see all the records entered in continuous form mode. Any insights
would be greatly appreciated.
 
Ken Snell said:
Not sure what you mean by "set the sub form to addnew". AddNew is a method
used by recordsets, and typically is not a property set for a subform.

Please give us more details about how you get to the subform and the code
that you're running before and after data entry.

--

Ken Snell
<MS ACCESS MVP>




Sorry - Let me more specific.

The main form is bound to a table called OrderMaster, it looks up a
customer and assigns an invoice number. The sub form is Bound to a table
called OrderSub, it allows the user to lookup a product number and finds the
correct price to use from another table - user enters quantity and it
calculates the total price for that item.

The mainform properties are allow additions, allow edits, allow deletions,
data entry = yes, Cycle = all records. Sub Form properties are allow
additions, allow edits, allow deletions, data entry = yes, cycle = all
records.

The form and subform were created via Wizard and worked fine. As luck would
have it - I had to make some changes and it does not want to work.

Since the last post I created a new Form and had the same problem - so data
related in some way?

More on symptoms - When I load the main form all controls work perfectly and
the record gets created in OrderMast tab at last field takes me to subForm,
all controls work fine on sub form at last field sub form should start a new
line - it skips back to the first field on the same line - giving me blank
fields. When I check the OrderSub the record was written. So basically it
looks as though it would if additions aren't allowed but the record gets
written.

Hope you can help - I am totally mysified.

I will attach code for the sub form:
Option Compare Database
Option Explicit

Private Sub cmbProductCode_LostFocus()
Me.txtProductName.Value = Me.cmbProductCode.Column(1)
Me.DiscountForItem.Enabled = True
End Sub



Private Sub ItemQuantity_Exit(Cancel As Integer)
Dim cn As ADODB.Connection
Dim rsTemp As ADODB.Recordset
Dim rsSpecial As ADODB.Recordset
Dim rsCust As ADODB.Recordset
Dim rsProd As ADODB.Recordset
Dim strSQL As String
Dim strSQL1 As String
Dim strSQL2 As String
Dim frm1 As Form
Dim lngDiscount As Currency
Dim intDiscount As Long
Dim cmd1 As ADODB.Command
Dim intPrice As Currency
Dim intCalc As Currency
Dim intProfit As Currency
Dim intPriceCode As Integer


Set frm1 = Forms("frmOrder")
Set cn = CurrentProject.Connection
Set rsTemp = New ADODB.Recordset
Set rsCust = New ADODB.Recordset
Set rsSpecial = New ADODB.Recordset
Set rsProd = New ADODB.Recordset
Set cmd1 = New ADODB.Command

rsTemp.CursorType = adOpenKeyset
rsTemp.LockType = adLockOptimistic

rsProd.CursorType = adOpenKeyset
rsProd.LockType = adLockOptimistic

rsSpecial.CursorType = adOpenKeyset
rsSpecial.LockType = adLockOptimistic

rsCust.CursorType = adOpenKeyset
rsCust.LockType = adLockOptimistic

' Write a temp record containing cust and prod

rsTemp.Open "tblTempSP", cn, , , adCmdTableDirect
rsTemp.AddNew
rsTemp("CustomerName") = frm1.cmbCustomerName
rsTemp("ProductCode") = Me.cmbProductCode
rsTemp.Update
Debug.Print "Created a temp record "
'Set up sql string to access special price table

strSQL = "SELECT SpecialPrice.CustomerName, SpecialPrice.ProductCode,
SpecialPrice.SpecialPrice" & _
" FROM SpecialPrice, tblTempSP" & _
" WHERE (((SpecialPrice.CustomerName)=[tblTempSP].[CustomerName]) AND
((SpecialPrice.ProductCode)=[tblTempSP].[ProductCode]))"


'look for special price - if one exists use it to get price

rsSpecial.Open strSQL, cn, , , adCmdTableDirect

If rsSpecial.BOF = True And rsSpecial.EOF = True Then GoTo CalculateDiscount

'Update ordermast totals with special price and disable discount field

lngDiscount = rsSpecial("SpecialPrice")
Me.ItemTotal = (lngDiscount * Me.ItemQuantity)
Me.ItemPrice = lngDiscount
Me.DiscountForItem.Enabled = False
Debug.Print "updated totals for Special Price"
GoTo CleanUp

' No Special Price found so Read cust and retreive pricecode and customer
discount

CalculateDiscount:

strSQL1 = "SELECT CustomerMaster.CustomerName,
CustomerMaster.DiscountPercent, CustomerMaster.PriceCode" & _
" FROM tblTempSP INNER JOIN CustomerMaster ON tblTempSP.CustomerName =
CustomerMaster.CustomerName" & _
" WHERE (((CustomerMaster.CustomerName)=[tblTempSP]![CustomerName]))"

rsCust.Open strSQL1, cn, , , adCmdTableDirect
intDiscount = rsCust("DiscountPercent")
Me.DiscountForItem = rsCust("DiscountPercent")
intPriceCode = rsCust("PriceCode")
rsCust.Close
Debug.Print "read the cust because there was no Special price"
' After cust read product and get price and check to see if discount is
allowed.

strSQL2 = "SELECT ProductMaster.ProductCode, tblTempSP.ProductCode,
ProductMaster.UnitCost, ProductMaster.DiscountAllowed, ProductMaster.NJPrice,
ProductMaster.EastCoastPrice, ProductMaster.StorePrice,
ProductMaster.VendingPrice, ProductMaster.MasterVendingPrice" & _
" FROM ProductMaster INNER JOIN tblTempSP ON ProductMaster.ProductCode =
tblTempSP.ProductCode" & _
" WHERE (((tblTempSP.ProductCode)=[ProductMaster].[Productcode]))"

rsProd.Open strSQL2, cn, , , adCmdTableDirect
Debug.Print "right after cust read, read prod"

'Choose correct Price

Select Case intPriceCode

Case 1
intPrice = rsProd("NJPrice")

Case 2
intPrice = rsProd("EastCoastPrice")

Case 3
intPrice = rsProd("StorePrice")

Case 4
intPrice = rsProd("VendingPrice")

Case 5
intPrice = rsProd("MasterVendingPrice")

Case 6
intPrice = rsProd("SparePrice1")

Case 7
intPrice = rsProd("SparePrice2")

End Select

'test if discount allowed

If rsProd("DiscountAllowed") = False Then GoTo NoDiscount

intCalc = ((intPrice * Me.ItemQuantity) * (intDiscount / 100))

Me.ItemTotal = (intPrice * Me.ItemQuantity) - intCalc
Me.ItemPrice = intPrice
GoTo UpdateTotals

NoDiscount:

Me.ItemPrice = intPrice

UpdateTotals:

frm1.OrderAmountTotal = frm1.OrderAmountTotal * (Me.ItemQuantity + intPrice)
frm1.UnitCostTotal = frm1.UnitCostTotal + (rsProd("UnitCost") *
Me.ItemQuantity)
intProfit = (frm1.OrderAmountTotal - frm1.UnitCostTotal)
frm1.OrderMargin = (frm1.UnitCostTotal / intProfit)
frm1.CurrentBalance = frm1.CurrentBalance + frm1.OrderAmountTotal

rsProd.Close
GoTo CleanUp



CleanUp:

rsTemp.Close
With cmd1
.ActiveConnection = CurrentProject.Connection
.CommandText = "DELETE * FROM tblTempSP"
.CommandType = adCmdText
.Execute
End With



rsSpecial.Close
Set cn = Nothing
Set rsTemp = Nothing
Set rsSpecial = Nothing
Set rsProd = Nothing
Set rsCust = Nothing
Set cmd1 = Nothing

End Sub

Private Sub txtProductName_GotFocus()
Me.ItemQuantity.SetFocus
End Sub
 
FatherBob said:
I came across a problem that I have set the sub form to addnew and continuous
form, however when entering data in the subform and reaching the last field
the next tab takes me to the beginning of the line I just typed ( I checked
the sub record and it gets written). I really want to get a new line and be
able to see all the records entered in continuous form mode. Any insights
would be greatly appreciated.


The Tab key is just cycling to the next (in this case a new)
record. It sounds like you have the subform's DataEntry
property set to Yes.
 
Marshall Barton said:
The Tab key is just cycling to the next (in this case a new)
record. It sounds like you have the subform's DataEntry
property set to Yes.

Regards Bob.
 
Marsh thanks for the suggestion but I have tried it with data entry =True
and data entry = False and no difference at all. I wondered if the form
had been corrupted - so I built a new one - same thing. I am probably
making some fundamental error - but I don't know what it is - nature
of the beast. Is it at all possible that it is a data related problem - I
looked at the tables and noticed that the Ordersub was not keyed on
Invoice number (which is the primary key of the Order master) does this
matter? is it worth changing the table and rebuilding the forms? Or am I kidding myself?

The Ordersub table should *contain* an Invoice Number field as a
foreign key, but that field should not be the Ordersub table's Primary
Key (if that's what you mean by "keyed on". You'ld use Invoice Number
as the Master Link Field and Child Link Field of the Subform control
to maintain the link. Is that what you have?

John W. Vinson[MVP]
 
John Vinson said:
The Ordersub table should *contain* an Invoice Number field as a
foreign key, but that field should not be the Ordersub table's Primary
Key (if that's what you mean by "keyed on". You'ld use Invoice Number
as the Master Link Field and Child Link Field of the Subform control
to maintain the link. Is that what you have?

John W. Vinson[MVP]

John, When I looked the suborder was not indexed (that is what I meant by Keyed) So I set it to indexed dups OK. I guess my question is - is it worth rebuilding now I have changed the key or am I just interfering with myself?
Since the last post I tried changing the sub form to a Datasheet - it works
fine! But it looks like S**T If you guys have no divine inspiration then I
will go with the datasheet and try and figure out what the quirk is with this
continuous form stuff.

Regards and many thanks Bob.
 
Just a couple of guesses here....

Is the height of the detail section more than what you need for displaying a
record? Shorten the height so that it's just as big as needed for a single
record.

Do you have vertical scroll bars "on" for the subform?

Did you try making the subform control itself (the control holding the
subform on the main form) taller?

If you press Shift-Tab when you end up in the first field in a new record,
does the subform scroll back up to the record that you just entered?

Is it possible that the record you added to the subform does not "match" the
linking criteria between your main form and the subform, or the subform's
Recordsource's filtering? If not, the record would "disappear" after entry.
--

Ken Snell
<MS ACCESS MVP>



FatherBob said:
Ken Snell said:
Not sure what you mean by "set the sub form to addnew". AddNew is a
method
used by recordsets, and typically is not a property set for a subform.

Please give us more details about how you get to the subform and the code
that you're running before and after data entry.

--

Ken Snell
<MS ACCESS MVP>




Sorry - Let me more specific.

The main form is bound to a table called OrderMaster, it looks up a
customer and assigns an invoice number. The sub form is Bound to a table
called OrderSub, it allows the user to lookup a product number and finds
the
correct price to use from another table - user enters quantity and it
calculates the total price for that item.

The mainform properties are allow additions, allow edits, allow deletions,
data entry = yes, Cycle = all records. Sub Form properties are allow
additions, allow edits, allow deletions, data entry = yes, cycle = all
records.

The form and subform were created via Wizard and worked fine. As luck
would
have it - I had to make some changes and it does not want to work.

Since the last post I created a new Form and had the same problem - so
data
related in some way?

More on symptoms - When I load the main form all controls work perfectly
and
the record gets created in OrderMast tab at last field takes me to
subForm,
all controls work fine on sub form at last field sub form should start a
new
line - it skips back to the first field on the same line - giving me blank
fields. When I check the OrderSub the record was written. So basically it
looks as though it would if additions aren't allowed but the record gets
written.

Hope you can help - I am totally mysified.

I will attach code for the sub form:
Option Compare Database
Option Explicit

Private Sub cmbProductCode_LostFocus()
Me.txtProductName.Value = Me.cmbProductCode.Column(1)
Me.DiscountForItem.Enabled = True
End Sub



Private Sub ItemQuantity_Exit(Cancel As Integer)
Dim cn As ADODB.Connection
Dim rsTemp As ADODB.Recordset
Dim rsSpecial As ADODB.Recordset
Dim rsCust As ADODB.Recordset
Dim rsProd As ADODB.Recordset
Dim strSQL As String
Dim strSQL1 As String
Dim strSQL2 As String
Dim frm1 As Form
Dim lngDiscount As Currency
Dim intDiscount As Long
Dim cmd1 As ADODB.Command
Dim intPrice As Currency
Dim intCalc As Currency
Dim intProfit As Currency
Dim intPriceCode As Integer


Set frm1 = Forms("frmOrder")
Set cn = CurrentProject.Connection
Set rsTemp = New ADODB.Recordset
Set rsCust = New ADODB.Recordset
Set rsSpecial = New ADODB.Recordset
Set rsProd = New ADODB.Recordset
Set cmd1 = New ADODB.Command

rsTemp.CursorType = adOpenKeyset
rsTemp.LockType = adLockOptimistic

rsProd.CursorType = adOpenKeyset
rsProd.LockType = adLockOptimistic

rsSpecial.CursorType = adOpenKeyset
rsSpecial.LockType = adLockOptimistic

rsCust.CursorType = adOpenKeyset
rsCust.LockType = adLockOptimistic

' Write a temp record containing cust and prod

rsTemp.Open "tblTempSP", cn, , , adCmdTableDirect
rsTemp.AddNew
rsTemp("CustomerName") = frm1.cmbCustomerName
rsTemp("ProductCode") = Me.cmbProductCode
rsTemp.Update
Debug.Print "Created a temp record "
'Set up sql string to access special price table

strSQL = "SELECT SpecialPrice.CustomerName, SpecialPrice.ProductCode,
SpecialPrice.SpecialPrice" & _
" FROM SpecialPrice, tblTempSP" & _
" WHERE (((SpecialPrice.CustomerName)=[tblTempSP].[CustomerName]) AND
((SpecialPrice.ProductCode)=[tblTempSP].[ProductCode]))"


'look for special price - if one exists use it to get price

rsSpecial.Open strSQL, cn, , , adCmdTableDirect

If rsSpecial.BOF = True And rsSpecial.EOF = True Then GoTo
CalculateDiscount

'Update ordermast totals with special price and disable discount field

lngDiscount = rsSpecial("SpecialPrice")
Me.ItemTotal = (lngDiscount * Me.ItemQuantity)
Me.ItemPrice = lngDiscount
Me.DiscountForItem.Enabled = False
Debug.Print "updated totals for Special Price"
GoTo CleanUp

' No Special Price found so Read cust and retreive pricecode and customer
discount

CalculateDiscount:

strSQL1 = "SELECT CustomerMaster.CustomerName,
CustomerMaster.DiscountPercent, CustomerMaster.PriceCode" & _
" FROM tblTempSP INNER JOIN CustomerMaster ON tblTempSP.CustomerName =
CustomerMaster.CustomerName" & _
" WHERE (((CustomerMaster.CustomerName)=[tblTempSP]![CustomerName]))"

rsCust.Open strSQL1, cn, , , adCmdTableDirect
intDiscount = rsCust("DiscountPercent")
Me.DiscountForItem = rsCust("DiscountPercent")
intPriceCode = rsCust("PriceCode")
rsCust.Close
Debug.Print "read the cust because there was no Special price"
' After cust read product and get price and check to see if discount is
allowed.

strSQL2 = "SELECT ProductMaster.ProductCode, tblTempSP.ProductCode,
ProductMaster.UnitCost, ProductMaster.DiscountAllowed,
ProductMaster.NJPrice,
ProductMaster.EastCoastPrice, ProductMaster.StorePrice,
ProductMaster.VendingPrice, ProductMaster.MasterVendingPrice" & _
" FROM ProductMaster INNER JOIN tblTempSP ON ProductMaster.ProductCode =
tblTempSP.ProductCode" & _
" WHERE (((tblTempSP.ProductCode)=[ProductMaster].[Productcode]))"

rsProd.Open strSQL2, cn, , , adCmdTableDirect
Debug.Print "right after cust read, read prod"

'Choose correct Price

Select Case intPriceCode

Case 1
intPrice = rsProd("NJPrice")

Case 2
intPrice = rsProd("EastCoastPrice")

Case 3
intPrice = rsProd("StorePrice")

Case 4
intPrice = rsProd("VendingPrice")

Case 5
intPrice = rsProd("MasterVendingPrice")

Case 6
intPrice = rsProd("SparePrice1")

Case 7
intPrice = rsProd("SparePrice2")

End Select

'test if discount allowed

If rsProd("DiscountAllowed") = False Then GoTo NoDiscount

intCalc = ((intPrice * Me.ItemQuantity) * (intDiscount / 100))

Me.ItemTotal = (intPrice * Me.ItemQuantity) - intCalc
Me.ItemPrice = intPrice
GoTo UpdateTotals

NoDiscount:

Me.ItemPrice = intPrice

UpdateTotals:

frm1.OrderAmountTotal = frm1.OrderAmountTotal * (Me.ItemQuantity +
intPrice)
frm1.UnitCostTotal = frm1.UnitCostTotal + (rsProd("UnitCost") *
Me.ItemQuantity)
intProfit = (frm1.OrderAmountTotal - frm1.UnitCostTotal)
frm1.OrderMargin = (frm1.UnitCostTotal / intProfit)
frm1.CurrentBalance = frm1.CurrentBalance + frm1.OrderAmountTotal

rsProd.Close
GoTo CleanUp



CleanUp:

rsTemp.Close
With cmd1
.ActiveConnection = CurrentProject.Connection
.CommandText = "DELETE * FROM tblTempSP"
.CommandType = adCmdText
.Execute
End With



rsSpecial.Close
Set cn = Nothing
Set rsTemp = Nothing
Set rsSpecial = Nothing
Set rsProd = Nothing
Set rsCust = Nothing
Set cmd1 = Nothing

End Sub

Private Sub txtProductName_GotFocus()
Me.ItemQuantity.SetFocus
End Sub
 
FatherBob said:
Marsh thanks for the suggestion but I have tried it with data entry =True and data entry = False and no difference at all. I wondered if the form had been corrupted - so I built a new one - same thing. I am probably making some fundamental error - but I don't know what it is - nature of the beast. Is it at all possible that it is a data related problem - I looked at the tables and noticed that the Ordersub was not keyed on Invoice number (which is the primary key of the Order master) does this matter? is it worth changing the table and rebuilding the forms? Or am I kidding myself?


If the subform's DataEntry property is set to Yes, then,
like John, I would suspect the LinkMaster/Child properties
are set inappropriately. The Link Master property should be
set to the main form text box bound to the OrderMaster table
primary key field. The Link Child property needs to be set
to the OrderSub table's order id foreign key.
 
Ken Snell said:
Just a couple of guesses here....

Is the height of the detail section more than what you need for displaying a
record? Shorten the height so that it's just as big as needed for a single
record.

Do you have vertical scroll bars "on" for the subform?

Did you try making the subform control itself (the control holding the
subform on the main form) taller?

If you press Shift-Tab when you end up in the first field in a new record,
does the subform scroll back up to the record that you just entered?

Is it possible that the record you added to the subform does not "match" the
linking criteria between your main form and the subform, or the subform's
Recordsource's filtering? If not, the record would "disappear" after entry.
--

Ken Snell
<MS ACCESS MVP>



FatherBob said:
Ken Snell said:
Not sure what you mean by "set the sub form to addnew". AddNew is a
method
used by recordsets, and typically is not a property set for a subform.

Please give us more details about how you get to the subform and the code
that you're running before and after data entry.

--

Ken Snell
<MS ACCESS MVP>

I came across a problem that I have set the sub form to addnew and
continuous
form, however when entering data in the subform and reaching the last
field
the next tab takes me to the beginning of the line I just typed ( I
checked
the sub record and it gets written). I really want to get a new line
and
be
able to see all the records entered in continuous form mode. Any
insights
would be greatly appreciated.




Sorry - Let me more specific.

The main form is bound to a table called OrderMaster, it looks up a
customer and assigns an invoice number. The sub form is Bound to a table
called OrderSub, it allows the user to lookup a product number and finds
the
correct price to use from another table - user enters quantity and it
calculates the total price for that item.

The mainform properties are allow additions, allow edits, allow deletions,
data entry = yes, Cycle = all records. Sub Form properties are allow
additions, allow edits, allow deletions, data entry = yes, cycle = all
records.

The form and subform were created via Wizard and worked fine. As luck
would
have it - I had to make some changes and it does not want to work.

Since the last post I created a new Form and had the same problem - so
data
related in some way?

More on symptoms - When I load the main form all controls work perfectly
and
the record gets created in OrderMast tab at last field takes me to
subForm,
all controls work fine on sub form at last field sub form should start a
new
line - it skips back to the first field on the same line - giving me blank
fields. When I check the OrderSub the record was written. So basically it
looks as though it would if additions aren't allowed but the record gets
written.

Hope you can help - I am totally mysified.

I will attach code for the sub form:
Option Compare Database
Option Explicit

Private Sub cmbProductCode_LostFocus()
Me.txtProductName.Value = Me.cmbProductCode.Column(1)
Me.DiscountForItem.Enabled = True
End Sub



Private Sub ItemQuantity_Exit(Cancel As Integer)
Dim cn As ADODB.Connection
Dim rsTemp As ADODB.Recordset
Dim rsSpecial As ADODB.Recordset
Dim rsCust As ADODB.Recordset
Dim rsProd As ADODB.Recordset
Dim strSQL As String
Dim strSQL1 As String
Dim strSQL2 As String
Dim frm1 As Form
Dim lngDiscount As Currency
Dim intDiscount As Long
Dim cmd1 As ADODB.Command
Dim intPrice As Currency
Dim intCalc As Currency
Dim intProfit As Currency
Dim intPriceCode As Integer


Set frm1 = Forms("frmOrder")
Set cn = CurrentProject.Connection
Set rsTemp = New ADODB.Recordset
Set rsCust = New ADODB.Recordset
Set rsSpecial = New ADODB.Recordset
Set rsProd = New ADODB.Recordset
Set cmd1 = New ADODB.Command

rsTemp.CursorType = adOpenKeyset
rsTemp.LockType = adLockOptimistic

rsProd.CursorType = adOpenKeyset
rsProd.LockType = adLockOptimistic

rsSpecial.CursorType = adOpenKeyset
rsSpecial.LockType = adLockOptimistic

rsCust.CursorType = adOpenKeyset
rsCust.LockType = adLockOptimistic

' Write a temp record containing cust and prod

rsTemp.Open "tblTempSP", cn, , , adCmdTableDirect
rsTemp.AddNew
rsTemp("CustomerName") = frm1.cmbCustomerName
rsTemp("ProductCode") = Me.cmbProductCode
rsTemp.Update
Debug.Print "Created a temp record "
'Set up sql string to access special price table

strSQL = "SELECT SpecialPrice.CustomerName, SpecialPrice.ProductCode,
SpecialPrice.SpecialPrice" & _
" FROM SpecialPrice, tblTempSP" & _
" WHERE (((SpecialPrice.CustomerName)=[tblTempSP].[CustomerName]) AND
((SpecialPrice.ProductCode)=[tblTempSP].[ProductCode]))"


'look for special price - if one exists use it to get price

rsSpecial.Open strSQL, cn, , , adCmdTableDirect

If rsSpecial.BOF = True And rsSpecial.EOF = True Then GoTo
CalculateDiscount

'Update ordermast totals with special price and disable discount field

lngDiscount = rsSpecial("SpecialPrice")
Me.ItemTotal = (lngDiscount * Me.ItemQuantity)
Me.ItemPrice = lngDiscount
Me.DiscountForItem.Enabled = False
Debug.Print "updated totals for Special Price"
GoTo CleanUp

' No Special Price found so Read cust and retreive pricecode and customer
discount

CalculateDiscount:

strSQL1 = "SELECT CustomerMaster.CustomerName,
CustomerMaster.DiscountPercent, CustomerMaster.PriceCode" & _
" FROM tblTempSP INNER JOIN CustomerMaster ON tblTempSP.CustomerName =
CustomerMaster.CustomerName" & _
" WHERE (((CustomerMaster.CustomerName)=[tblTempSP]![CustomerName]))"

rsCust.Open strSQL1, cn, , , adCmdTableDirect
intDiscount = rsCust("DiscountPercent")
Me.DiscountForItem = rsCust("DiscountPercent")
intPriceCode = rsCust("PriceCode")
rsCust.Close
Debug.Print "read the cust because there was no Special price"
' After cust read product and get price and check to see if discount is
allowed.

strSQL2 = "SELECT ProductMaster.ProductCode, tblTempSP.ProductCode,
ProductMaster.UnitCost, ProductMaster.DiscountAllowed,
ProductMaster.NJPrice,
ProductMaster.EastCoastPrice, ProductMaster.StorePrice,
ProductMaster.VendingPrice, ProductMaster.MasterVendingPrice" & _
" FROM ProductMaster INNER JOIN tblTempSP ON ProductMaster.ProductCode =
tblTempSP.ProductCode" & _
" WHERE (((tblTempSP.ProductCode)=[ProductMaster].[Productcode]))"

rsProd.Open strSQL2, cn, , , adCmdTableDirect
Debug.Print "right after cust read, read prod"

'Choose correct Price

Select Case intPriceCode

Case 1
intPrice = rsProd("NJPrice")

Case 2
intPrice = rsProd("EastCoastPrice")

Case 3
intPrice = rsProd("StorePrice")

Case 4
intPrice = rsProd("VendingPrice")

Case 5
intPrice = rsProd("MasterVendingPrice")

Case 6
intPrice = rsProd("SparePrice1")

Case 7
intPrice = rsProd("SparePrice2")

End Select

'test if discount allowed

If rsProd("DiscountAllowed") = False Then GoTo NoDiscount

intCalc = ((intPrice * Me.ItemQuantity) * (intDiscount / 100))

Me.ItemTotal = (intPrice * Me.ItemQuantity) - intCalc
Me.ItemPrice = intPrice
GoTo UpdateTotals

NoDiscount:

Me.ItemPrice = intPrice

UpdateTotals:

frm1.OrderAmountTotal = frm1.OrderAmountTotal * (Me.ItemQuantity +
intPrice)
frm1.UnitCostTotal = frm1.UnitCostTotal + (rsProd("UnitCost") *
Me.ItemQuantity)
intProfit = (frm1.OrderAmountTotal - frm1.UnitCostTotal)
frm1.OrderMargin = (frm1.UnitCostTotal / intProfit)
frm1.CurrentBalance = frm1.CurrentBalance + frm1.OrderAmountTotal

rsProd.Close
GoTo CleanUp



CleanUp:

rsTemp.Close
With cmd1
.ActiveConnection = CurrentProject.Connection
.CommandText = "DELETE * FROM tblTempSP"
.CommandType = adCmdText
.Execute
End With



rsSpecial.Close
Set cn = Nothing
Set rsTemp = Nothing
Set rsSpecial = Nothing
Set rsProd = Nothing
Set rsCust = Nothing
Set cmd1 = Nothing

End Sub

Private Sub txtProductName_GotFocus()
Me.ItemQuantity.SetFocus
End Sub


Ken - Many thanks for your suggestions - I have got it working - for the edification of anyone reading this, here's the problem and solution.

It seems I created a form/subform, completed all customization (extensive)
then made the mistake of changing one of the tables. The Form/subform were
smart enough to see a problem. However when I corrected the problem with the
table the Form/subform is not smart enough to realize that the problem no
longer exists.

Solution create new form/subform and painfully cut and paste controls and
code till it works again. Thanks again Ken - sometimes you need someone else
to shine a light in the dark.

Regards Bob.
 
if you're using A2000 or newer, Name AutoCorrect might be the cause of the
database failing to recognize that you've changed a table "back" from a
previous change. it also causes plenty of other problems, so if you haven't
turned it off already, suggest you do that now.

from the database window, on the menu bar, click Tools | Options | General
tab and UNcheck the box next to Track name AutoCorrect info.

hth


FatherBob said:
Ken Snell said:
Just a couple of guesses here....

Is the height of the detail section more than what you need for displaying a
record? Shorten the height so that it's just as big as needed for a single
record.

Do you have vertical scroll bars "on" for the subform?

Did you try making the subform control itself (the control holding the
subform on the main form) taller?

If you press Shift-Tab when you end up in the first field in a new record,
does the subform scroll back up to the record that you just entered?

Is it possible that the record you added to the subform does not "match" the
linking criteria between your main form and the subform, or the subform's
Recordsource's filtering? If not, the record would "disappear" after entry.
--

Ken Snell
<MS ACCESS MVP>



FatherBob said:
:

Not sure what you mean by "set the sub form to addnew". AddNew is a
method
used by recordsets, and typically is not a property set for a subform.

Please give us more details about how you get to the subform and the code
that you're running before and after data entry.

--

Ken Snell
<MS ACCESS MVP>

I came across a problem that I have set the sub form to addnew and
continuous
form, however when entering data in the subform and reaching the last
field
the next tab takes me to the beginning of the line I just typed ( I
checked
the sub record and it gets written). I really want to get a new line
and
be
able to see all the records entered in continuous form mode. Any
insights
would be greatly appreciated.




Sorry - Let me more specific.

The main form is bound to a table called OrderMaster, it looks up a
customer and assigns an invoice number. The sub form is Bound to a table
called OrderSub, it allows the user to lookup a product number and finds
the
correct price to use from another table - user enters quantity and it
calculates the total price for that item.

The mainform properties are allow additions, allow edits, allow deletions,
data entry = yes, Cycle = all records. Sub Form properties are allow
additions, allow edits, allow deletions, data entry = yes, cycle = all
records.

The form and subform were created via Wizard and worked fine. As luck
would
have it - I had to make some changes and it does not want to work.

Since the last post I created a new Form and had the same problem - so
data
related in some way?

More on symptoms - When I load the main form all controls work perfectly
and
the record gets created in OrderMast tab at last field takes me to
subForm,
all controls work fine on sub form at last field sub form should start a
new
line - it skips back to the first field on the same line - giving me blank
fields. When I check the OrderSub the record was written. So basically it
looks as though it would if additions aren't allowed but the record gets
written.

Hope you can help - I am totally mysified.

I will attach code for the sub form:
Option Compare Database
Option Explicit

Private Sub cmbProductCode_LostFocus()
Me.txtProductName.Value = Me.cmbProductCode.Column(1)
Me.DiscountForItem.Enabled = True
End Sub



Private Sub ItemQuantity_Exit(Cancel As Integer)
Dim cn As ADODB.Connection
Dim rsTemp As ADODB.Recordset
Dim rsSpecial As ADODB.Recordset
Dim rsCust As ADODB.Recordset
Dim rsProd As ADODB.Recordset
Dim strSQL As String
Dim strSQL1 As String
Dim strSQL2 As String
Dim frm1 As Form
Dim lngDiscount As Currency
Dim intDiscount As Long
Dim cmd1 As ADODB.Command
Dim intPrice As Currency
Dim intCalc As Currency
Dim intProfit As Currency
Dim intPriceCode As Integer


Set frm1 = Forms("frmOrder")
Set cn = CurrentProject.Connection
Set rsTemp = New ADODB.Recordset
Set rsCust = New ADODB.Recordset
Set rsSpecial = New ADODB.Recordset
Set rsProd = New ADODB.Recordset
Set cmd1 = New ADODB.Command

rsTemp.CursorType = adOpenKeyset
rsTemp.LockType = adLockOptimistic

rsProd.CursorType = adOpenKeyset
rsProd.LockType = adLockOptimistic

rsSpecial.CursorType = adOpenKeyset
rsSpecial.LockType = adLockOptimistic

rsCust.CursorType = adOpenKeyset
rsCust.LockType = adLockOptimistic

' Write a temp record containing cust and prod

rsTemp.Open "tblTempSP", cn, , , adCmdTableDirect
rsTemp.AddNew
rsTemp("CustomerName") = frm1.cmbCustomerName
rsTemp("ProductCode") = Me.cmbProductCode
rsTemp.Update
Debug.Print "Created a temp record "
'Set up sql string to access special price table

strSQL = "SELECT SpecialPrice.CustomerName, SpecialPrice.ProductCode,
SpecialPrice.SpecialPrice" & _
" FROM SpecialPrice, tblTempSP" & _
" WHERE (((SpecialPrice.CustomerName)=[tblTempSP].[CustomerName]) AND
((SpecialPrice.ProductCode)=[tblTempSP].[ProductCode]))"


'look for special price - if one exists use it to get price

rsSpecial.Open strSQL, cn, , , adCmdTableDirect

If rsSpecial.BOF = True And rsSpecial.EOF = True Then GoTo
CalculateDiscount

'Update ordermast totals with special price and disable discount field

lngDiscount = rsSpecial("SpecialPrice")
Me.ItemTotal = (lngDiscount * Me.ItemQuantity)
Me.ItemPrice = lngDiscount
Me.DiscountForItem.Enabled = False
Debug.Print "updated totals for Special Price"
GoTo CleanUp

' No Special Price found so Read cust and retreive pricecode and customer
discount

CalculateDiscount:

strSQL1 = "SELECT CustomerMaster.CustomerName,
CustomerMaster.DiscountPercent, CustomerMaster.PriceCode" & _
" FROM tblTempSP INNER JOIN CustomerMaster ON tblTempSP.CustomerName =
CustomerMaster.CustomerName" & _
" WHERE (((CustomerMaster.CustomerName)=[tblTempSP]![CustomerName]))"

rsCust.Open strSQL1, cn, , , adCmdTableDirect
intDiscount = rsCust("DiscountPercent")
Me.DiscountForItem = rsCust("DiscountPercent")
intPriceCode = rsCust("PriceCode")
rsCust.Close
Debug.Print "read the cust because there was no Special price"
' After cust read product and get price and check to see if discount is
allowed.

strSQL2 = "SELECT ProductMaster.ProductCode, tblTempSP.ProductCode,
ProductMaster.UnitCost, ProductMaster.DiscountAllowed,
ProductMaster.NJPrice,
ProductMaster.EastCoastPrice, ProductMaster.StorePrice,
ProductMaster.VendingPrice, ProductMaster.MasterVendingPrice" & _
" FROM ProductMaster INNER JOIN tblTempSP ON ProductMaster.ProductCode =
tblTempSP.ProductCode" & _
" WHERE (((tblTempSP.ProductCode)=[ProductMaster].[Productcode]))"

rsProd.Open strSQL2, cn, , , adCmdTableDirect
Debug.Print "right after cust read, read prod"

'Choose correct Price

Select Case intPriceCode

Case 1
intPrice = rsProd("NJPrice")

Case 2
intPrice = rsProd("EastCoastPrice")

Case 3
intPrice = rsProd("StorePrice")

Case 4
intPrice = rsProd("VendingPrice")

Case 5
intPrice = rsProd("MasterVendingPrice")

Case 6
intPrice = rsProd("SparePrice1")

Case 7
intPrice = rsProd("SparePrice2")

End Select

'test if discount allowed

If rsProd("DiscountAllowed") = False Then GoTo NoDiscount

intCalc = ((intPrice * Me.ItemQuantity) * (intDiscount / 100))

Me.ItemTotal = (intPrice * Me.ItemQuantity) - intCalc
Me.ItemPrice = intPrice
GoTo UpdateTotals

NoDiscount:

Me.ItemPrice = intPrice

UpdateTotals:

frm1.OrderAmountTotal = frm1.OrderAmountTotal * (Me.ItemQuantity +
intPrice)
frm1.UnitCostTotal = frm1.UnitCostTotal + (rsProd("UnitCost") *
Me.ItemQuantity)
intProfit = (frm1.OrderAmountTotal - frm1.UnitCostTotal)
frm1.OrderMargin = (frm1.UnitCostTotal / intProfit)
frm1.CurrentBalance = frm1.CurrentBalance + frm1.OrderAmountTotal

rsProd.Close
GoTo CleanUp



CleanUp:

rsTemp.Close
With cmd1
.ActiveConnection = CurrentProject.Connection
.CommandText = "DELETE * FROM tblTempSP"
.CommandType = adCmdText
.Execute
End With



rsSpecial.Close
Set cn = Nothing
Set rsTemp = Nothing
Set rsSpecial = Nothing
Set rsProd = Nothing
Set rsCust = Nothing
Set cmd1 = Nothing

End Sub

Private Sub txtProductName_GotFocus()
Me.ItemQuantity.SetFocus
End Sub


Ken - Many thanks for your suggestions - I have got it working - for the
edification of anyone reading this, here's the problem and solution.
 
Back
Top