docmd methods not always executing

lvmoore

Registered User.
Local time
Today, 06:25
Joined
Sep 25, 2010
Messages
13
What causes docmd methods to not execute? For some reason the docmd method in both the frmShipSwitch and frmShipment code was being moved through without doing anything. For a bit it will work and then if I do something in the code like add a message box it will stop working again. Why would this happen?
At least the gotorecord method works sometimes
I've never used the findrecord method before so I'm not sure what I'm doing wrong. Note that both are popup forms with frmShipSwitch being modal.
Below is code found on button I press on frmShipSwitch to set open args for Shipment

Code:
Private Sub lblOK_Click()
Dim strOrder As String 'variable for the Order Number
Dim strStart As String 'variable for start date range
Dim strEnd As String 'variable for end date range
Dim strfrm As String 'variable for frmShipment
 
Me.txttest.SetFocus
Me!lblOK.SpecialEffect = 2
strStart = Nz(Me.txtStart, 0)
strEnd = Nz(Me.txtEnd, 0)
strOrder = Nz(Me.txtOrder, 0)
strfrm = "frmShipment"
 
'--no order number is given use start and end date ranges
If strOrder = 0 Then
 
    '--close the ShipSwitchboard
    RunCommand acCmdClose
    '--open another popup that shows list of possible shipments ** right   now just opens frmShipment**
    DoCmd.OpenForm strfrm, , , , , , 2
    '--there is an order number given
Else
    '--close the ShipSwitchboard
    RunCommand acCmdClose
    '--open the shipments form
    DoCmd.OpenForm strfrm, , , , , , strOrder
End If
End Sub

Below is the code contained in the frmShipment Form

Code:
Private Sub Form_Load()
Dim str As String 'variable for open args
Dim strON As String 'variable for the string with quotes
 
str = Nz(Me.OpenArgs, 0)
Me.OrderNumber.SetFocus
'--if you arrive from ShipSwich New Shipment
If str = 1 Then
    DoCmd.GoToRecord , , acNewRec
'--if you arrive from somewhere else
Else
    '--you arrive from object list
    If str = 0 Then
        DoCmd.GoToRecord , , acNewRec
 
     '--everything else
    Else
        '--go to the control that will be searched through
        strON = Chr(34) & str & Chr(34)
        MsgBox "You are finding " & str
        Me.OrderNumber.SetFocus
        DoCmd.FindRecord , strON, , False, , acCurrent
 
    End If
End If
End Sub
 
I compiled the code and compacted and repaired the database. the gotorecord method is now working but I still must have some sort of syntax error with my findrecord. Any ideas?
 
It would appear that you have not actually told the FindRecord what to find.
Code:
DoCmd.FindRecord [COLOR="Red"][B]"What To Find"[/B][/COLOR], strON, , False, , acCurrent
The highlighted section has not been specified in your code.
 
I'm seeing what you mean. I haven't actually set the strON. By the look of it to me right now I also seem to have a comma in the string of arguments before strON which should not be there. Would I also need to put quotes around strON...or double quotes since it is a string (or put one set when I set it and one in the arguments...strings get me every time)?

Thanks
 
Given that strON is a variable you won't need to enclose it in double quotes. You would only need the Double quotes if you where to hard code the What to find.
 

Users who are viewing this thread

Back
Top Bottom