Redirecting to another form when form is blank

  • Thread starter Thread starter DJJ
  • Start date Start date
D

DJJ

I am accessing individual records in an Physical Inventory Form by selecting
the record from a drop down list in a Search Form. It works well until I
select a record that has no current inventory on hand and then my Physical
Inventory Form displays blank. When this happens I would like to direct the
user to yet another form called Add Inventory. How do I do that?



I tried to put some code in the Form Current Event in the Physical Inventory
Form that checks the current record and then give the user an option to be
redirected but I'm sure I got it all wrong.



Private Sub Form_Current()



Dim Msg, Style, Title, Response

Msg = "Do you want to add this Item Number to the inventory?"

Style = vbYesNo

Title = "Item Not Found"



Dim lngrecordnum As Long



lngrecordnum = Me.Form.CurrentRecord



If lngrecordnum = Null Then

Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then

DoCmd.OpenForm "frmAddInventory", acNormal, , ,
acFormAdd

Else

DoCmd.Close acForm, "frmPhysInventory"

Exit Sub

End If

End If



End Sub
 
DJJ said:
I am accessing individual records in an Physical Inventory Form by selecting
the record from a drop down list in a Search Form. It works well until I
select a record that has no current inventory on hand and then my Physical
Inventory Form displays blank. When this happens I would like to direct the
user to yet another form called Add Inventory. How do I do that?

I tried to put some code in the Form Current Event in the Physical Inventory
Form that checks the current record and then give the user an option to be
redirected but I'm sure I got it all wrong.

Private Sub Form_Current()
Dim Msg, Style, Title, Response
Dim lngrecordnum As Long

Msg = "Do you want to add this Item Number to the inventory?"
Style = vbYesNo
Title = "Item Not Found"

lngrecordnum = Me.Form.CurrentRecord
If lngrecordnum = Null Then

Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
DoCmd.OpenForm "frmAddInventory", acNormal, , ,
acFormAdd

Else
DoCmd.Close acForm, "frmPhysInventory"
Exit Sub
End If
End If
End Sub


Instead of using:
lngrecordnum = Me.Form.CurrentRecord
If lngrecordnum = Null Then

check if the form has any records:
If Me.Recordset.RecordCount > 0 Then

I can't see why the Current event would be appropriate.
How your search form interacts with this form was
unexplained, but it seems like you should at least see if
you can use the form's Load event or some other mechanism to
run the code.
 
Marshall Barton said:
Instead of using:
lngrecordnum = Me.Form.CurrentRecord
If lngrecordnum = Null Then

check if the form has any records:
If Me.Recordset.RecordCount > 0 Then

I can't see why the Current event would be appropriate.
How your search form interacts with this form was
unexplained, but it seems like you should at least see if
you can use the form's Load event or some other mechanism to
run the code.

Yes, I descovered that I could verify if the primary key field was null
(Physical Inventory Form) from the Search Form Combobox afterupdate event
and then redirect to the user to Add Inventory Form.

I found that tip from an earlier post on this group through a google search

Thanks for the reply
 
Back
Top