Blank Rows In Table

bossmack916

New member
Local time
Yesterday, 18:34
Joined
Mar 28, 2012
Messages
6
I have a "Main Form" with a "Add New Order" button. When I click on "Add New Order" , the "Orders" form opens and allows you to add a new order. On this form is an "Order ID" field that keep record of the order number. However, everytime I open a new "Orders" form, the order ID skips a number and a blank row is populated in the "Orders" Table, which the form is linked to. Why does this occur? How can I prevent this from happening? Below is the code I have for the "Add New Order" button on the "Main" form.


Private Sub cmdAddOrder_Click()
On Error GoTo Err_cmdAddOrders_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim intOrderID As Integer

intOrderID = lngGetNewOrderID


stLinkCriteria = "Orderid = " & lngGetNewOrderID

stDocName = "FrmOrders"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdAddOrders_Click:
Exit Sub

Err_cmdAddOrders_Click:
MsgBox Err.Description
Resume Exit_cmdAddOrders_Click
End Sub
 
The code you posted, in and of itself, doesn't do anything except open a form to a given record. However, it does use what appears to be a user defined function (lngGetNewOrderID) to determine which record to open. Since you're that function twice, that's probably why you're getting a blank record.

Code:
intOrderID = lngGetNewOrderID [COLOR="Red"]<<< you run the function once here[/COLOR]


stLinkCriteria = "Orderid = " & lngGetNewOrderID  [COLOR="red"]<<< and again here[/COLOR]

Change it as follows and see if that solves your problem

Code:
intOrderID = lngGetNewOrderID


stLinkCriteria = "Orderid = " & [COLOR="red"]intOrderID[/COLOR]
 

Users who are viewing this thread

Back
Top Bottom