run time error 2105 you can't go to specified record

SJB67

Registered User.
Local time
Today, 21:51
Joined
Sep 18, 2015
Messages
24
Hello,

I hope someone can help.

I have a sales order system.

My main data entry form has the following setup:

frmNewSale, sfrmSalesHeader, sfrmSalesLine.

The onload event sets sfrmSalesHeader to the next invoice number.

In certain circumstances I wish to recall an existing sales invoice and amend it. The record is identified in a separate form LQSelect

In the onload event of sfrmSalesHeader I have put the following:

Private Sub Form_Load()
'if form LQ select is open go to selected record
If Application.SysCmd(acSysCmdGetObjectState, acForm, "frmLQSelect") = acObjStateOpen Then
Dim LQRef As Long
LQRef = Forms!frmLQselect!txtSalesInvID

Me!txtSalesInvID.SetFocus

DoCmd.GoToRecord , , acGoTo, LQRef

Else

DoCmd.GoToRecord , , acNewRec
Me!txtSalesInvID = DMax("[SalesInvID]", "tblSalesHeader") + 1

End If

End Sub

The line highlighted red is where the debugger highlights the issue.
In its table SalesInvID is a long integer.

Any ideas? I have been searching for 2 days now with no joy.

Many thanks :confused:
 
Is your form set to Data Entry in its properties? If so this opens it with a new record only?
 
Nope, and allow edits is Yes.
 
Ah - wait - being thick.
Syntax expression .GoToRecord(ObjectType, ObjectName, Record, Offset)

You aren't searching for a record, you are currently using your ID as an offset- that won't work.
 
Yes - I have read differing ideas on this, some saying possible some not.

Do you know of a way to go to a specific record referenced in another form?

Thanks
 
There are a number of ways.
If the form isn't already open, you can pass the ID as an OpenArgs this has the benefit of allowing you to go to your new record if there aren't any args passed (e.g. form opened normally).

Personally, I would put a command button to open the form from your search form with the openArgs set to your search result.
 
I'll give it a go - thanks for your help
 
No problem - if you get stuck come back to us.
 

Users who are viewing this thread

Back
Top Bottom