Pesky button issue

B

Brad Holderman

Greetings,

I am currently using Access 2000 to run a document image database and have
run into a bit of a issue with coding in some buttons.


For the most part, starting with a switchboard menu I want to open a form
running off a query to search records. My goal is if No records are found,
the code takes me into the form with a new record. If cancel is clicked, I
want to go back out to the previous switchboard.

The first batch of code is what is running so far. But there are 2 things.
First, for some reason, coding the vbCancel button to open a new record
causes the OK button to do this, and vice versa which seems backwards to what
I am trying to write.

Second, in trying to write a second If..Then for the actual Cancel button,
it simply passes me into the form, but I want to go back out to the
switchboard. I pasted what I wrote in my attempts at that, as the "Second
try." Any help would be appreciated.

Code running so far:
Private Sub Form_Open(Cancel As Integer)
Dim stDocName As String
Dim strMessage As String
Dim intOptions As Integer
Dim bytChoice As Byte

stDocName = "frmPerCustomer"
If Me.Recordset.RecordCount = 0 Then
strMessage = "Job Not found, click OK to Continue."
intOptions = vbQuestion + vbOKCancel
bytChoice = MsgBox(strMessage, intOptions)

If bytChoice = vbCancel Then
DoCmd.Close
DoCmd.OpenForm stDocName, acNewRecord
End If

End If
End Sub

Second try:

Private Sub Form_Open(Cancel As Integer)
Dim stDocName As String
Dim strMessage As String
Dim intOptions As Integer
Dim bytChoice As Byte

stDocName = "frmPerCustomer"
If Me.Recordset.RecordCount = 0 Then
strMessage = "Job Not found, click OK to Continue."
intOptions = vbQuestion + vbOKCancel
bytChoice = MsgBox(strMessage, intOptions)

If bytChoice = vbOK Then
DoCmd.Close
DoCmd.OpenForm stDocName, acNewRecord
End If

If bytChoice = vbCancel Then
DoCmd.Close
DoCmd.OpenForm "frmSearchMenu", acNormal
End If
End Sub
 
B

Brad Holderman

Greetings,

Just an update, I altered the code just a bit. Now the Cancel button works
as it should, but the OK button now tries to run the query the form is based
on. The code is written in the "On Open" event. Again, I'm almost there and
would appreciate nay nudge in the right direction.

Cheers,
Brad

My revised code:

Private Sub Form_Open(Cancel As Integer)
Dim stDocName As String
Dim strMessage As String
Dim intOptions As Integer
Dim bytChoice As Byte

stDocName = "frmPerCustomer"
If Me.Recordset.RecordCount = 0 Then
strMessage = "Job Not found, click OK to Continue."
intOptions = vbQuestion + vbOKCancel
bytChoice = MsgBox(strMessage, intOptions)

If bytChoice = vbOK Then
DoCmd.Close
DoCmd.OpenForm stDocName, acNewRecord
End If

If bytChoice = vbCancel Then
DoCmd.Close
DoCmd.OpenForm "frmSearchMenu", acNormal
End If
End If

End Sub
 

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