By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,807 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,807 IT Pros & Developers. It's quick & easy.

Access Form with some VB 6.0 code

P: 37
ok. I have a form that I have created in Access and I am using a bit of VB 6.0 code behind the scenes.
On the form I have a combo box called "Payment Method" and in the combo box the choices are: check, cash, free. Then I have a textbox called "CheckNum" for the user to enter a check number when "check" is chosen. What I'm wanting to do is - when the user chooses "check" from the combo box I want it to prompt the user to enter a check number if they have by passed that field. Here is the code that I have and it is not working. Please help!
Expand|Select|Wrap|Line Numbers
  1. Private Sub PrintRec_Click()
  2. On Error GoTo Err_PrintRec_Click
  3.  
  4. Dim rstTrans As New ADODB.Recordset
  5. Dim fld As ADODB.Field
  6. Dim strField As String
  7. Dim curCount As Currency
  8.  
  9. /////// Here is the code in question
  10.  If Me.cboPaymentMethod = "Check" And CheckNum.Text = "" Then 'Check number not entered
  11.          MsgBox "You must enter a check no."
  12.     CheckNum.SetFocus
  13.  
  14. End If
  15.  
  16.  
  17. rstTrans.Open "dbo_tbl_Transactions", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
  18.  
  19.     If IsNull(Me.TempTransNumID.value) Then
  20.     'this is new record
  21.     rstTrans.AddNew
  22.     Else
  23.     'to stay on the record that was just inserted for editing
  24.     rstTrans.Find ("TransNumID=" + Str$(Me.TempTransNumID))
  25.     End If
  26.  
  27.  
  28. rstTrans!TransDate = Me.TransDate
  29. rstTrans!CustomerName = Me.CustomerName
  30. rstTrans!VehType = Me.VehType
  31. rstTrans!TktType = Me.TktType
  32. rstTrans!Auth_By = Me.AuthBy
  33. rstTrans!Quantity = Me.Quantity
  34. rstTrans!SHtkt1 = Me.SHtkt1
  35. rstTrans!SHtkt2 = Me.SHtkt2
  36. rstTrans!HRtkt1 = Me.HRtkt1
  37. rstTrans!HRtkt2 = Me.HRtkt2
  38. rstTrans!TransPayAmt = Me.TransPayAmt
  39. rstTrans!PaymentType = Me.txtPaymentType
  40. rstTrans!PaymentMethod = Me.cboPaymentMethod
  41. rstTrans!CheckNum = Me.CheckNum
  42. rstTrans!TransReceiptMemo = Me.TransReceiptMemo
  43. rstTrans!TransEntryTime = Now()
  44. rstTrans!TransEntryUserID = appUser
  45.  
  46.  
  47.  
  48.  
  49. rstTrans.Update
  50. 'this was a new record so update the form value of TransNumID for edit
  51. If IsNull(rstTrans!TransNumID.value) <> True Then
  52.     Me.TempTransNumID = rstTrans!TransNumID.value
  53. End If
  54.  
  55.  
  56. whereClause = "NewQryShuttleHandiRideReceipt.TransNumID" & " = " & rstTrans!TransNumID
  57.  
  58. 'DoCmd.OpenReport "RptShuttle HandiRide Receipt", acViewNormal, , whereClause
  59.  
  60. rstTrans.Close
  61.  
  62. Set rstTrans = Nothing
  63. Me.cmdAddRec.Enabled = True
  64.  
  65. Exit_PrintRec_Click:
  66.     MsgBox "Record Successfully Saved! Printing Receipt."
  67.     Exit Sub
  68.  
  69. Err_PrintRec_Click:
  70.     MsgBox Err.Description
  71.     Resume Exit_PrintRec_Click
  72.  
  73. End Sub
Oct 11 '07 #1
Share this Question
Share on Google+
2 Replies


nico5038
Expert 2.5K+
P: 3,072
The best approach is to have two buttons on the form:
[Cancel] and [Save]
Your test for the Check text to be filled should be performed when the [Save] button is pressed and the combo equals "Check". This way the user can enter the Checktext and the "Check" value in the combo in any sequence.

Getting the idea ?

Nic;o)
Oct 11 '07 #2

missinglinq
Expert 2.5K+
P: 3,532
And just to clarify things, if your code is behind an Access form, it is VBA (Visual Basic for Applications) not VB6! While VBA was developed from standard Visual Basic, there are differences which, at times, are substantial. All functions available in one are not available in the other, and some identically named functions behave differently, depending on which of the two languages you're referring to and even which version of Access you're using.

Be sure to always post Access code questions here as you did, rather than in the Visual Basic forum.

Welcome to TheScripts!

Linq ;0)>
Oct 11 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.