Find record created in form load

B

Biggles

There may be many thing wrong with this, so I apologize from the start. I
have one form that builds the reference number, and I want to transfer that
and other information to the Main Input Form, and then move to that record in
the Main Input Form. Right now, the form opens to the first record. I have
the following in the Form_Load event:

Private Sub Form_Load()

If Me.OpenArgs = 1 Then
DoCmd.GoToRecord , , acNewRec
[Issue Entry Date] = Now()

Me.Issue_Reference_Number = Forms!frmnewissue_setup.Text5
Me.division = Forms!frmnewissue_setup.Combo3
Me.Year = Forms!frmnewissue_setup.Text9
Me.Combo206 = Forms!frmnewissue_setup.Combo11

'Go to this issue
If Me.Dirty Then Me.Dirty = False
Dim rs As Object
Dim srchstr As String

Set rs = Me.Recordset.Clone
srchstr = "[Issue Reference Number] = '" &
Forms!frmnewissue_setup.Text5 & "'"

rs.FindFirst srchstr
If rs.EOF = True Then
Debug.Print "no record"
End If

Me.Detail.Visible = True
Me.Bookmark = rs.Bookmark


DoCmd.Close acForm, "frmnewissue_setup"

End If
DoCmd.Maximize

End Sub

The code to open this is:
Dim formname As String

formname = "master input form"

DoCmd.OpenForm formname, , , , , , 1

What am I missing?
 
S

Steve Sanford

You really should read up on "Naming Conventions"..... :D

I played around with your code a little. Not quite sure what your question
is....

See if this helps:

' --------- code begin------------
Private Sub Form_Load()

If Me.OpenArgs <> 1 Then
DoCmd.Maximize
Exit Sub
End If

On Error GoTo Err_MyBad

DoCmd.GoToRecord , , acNewRec
' Now() is the date and time
' use Date() if you only want the date
[Issue Entry Date] = Now()

Me.Issue_Reference_Number = Forms!frmnewissue_setup.Text5
Me.division = Forms!frmnewissue_setup.Combo3

' ** "YEAR'"is a reserved word!!! **
' changed to "txtYear"
Me.txtYear = Forms!frmnewissue_setup.Text9
Me.Combo206 = Forms!frmnewissue_setup.Combo11

'save record
If Me.Dirty Then
Me.Dirty = False
End If

'find this issue
Dim rs As dao.Recordset
Dim srchstr As String

Set rs = Me.Recordset.Clone
srchstr = "[Issue Reference Number] = '" & Forms!frmnewissue_setup.Text5
& "'"

rs.FindFirst srchstr
' always check the NoMatch property after a Find, Findfirst, etc.
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
' delete the following TWO lines after debugging is complete
Else
Debug.Print "no record"

End If

Me.Detail.Visible = True

Exit_MyBad:
'clean up
rs.Close
Set rs = Nothing

DoCmd.Close acForm, "frmnewissue_setup"

Exit Sub

Err_MyBad:

MsgBox Err.Description
Resume Exit_MyBad

End Sub
' --------- code end--------------

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top