PDA

View Full Version : Calling Public Variables



FrymanTCU
05-27-2008, 08:08 AM
Ok I have a form that runs a search function to pull in selected records to a subform. Then on the subform I have a cmdButton that is going to modify the selected record. But I wanted to add comments to the record so I created a seperat form that is basically just a text box with a OK and Cancel button. But I need to set the Audit reason, AudRsn to different text depending on which button they click. I have tried this a couple different ways but I keep getting an error message. I'm sure the mistake is something small so if anyone can help or point me to a good article on public variable/strings I would be very greatful.
Thanks,
Rich

Search Main Form
Public Sub cmdAccptInError_DblClick(Cancel As Integer)
Dim AudRsn As String
CallingAccptError AudRsn
DoCmd.OpenForm "Audit Comments"
End Sub
Public Sub CallingAccptError(AudErrorRsn)
AudErrorRsn = "Accepted in Error"
End Sub


TextBox Form
Private Sub cmdOKmemo_Click()
Dim myComments As String
myComments = " & Me.txtAuditNotes.Text & "
Call MyLogSQL
DoCmd.Close acForm, "Audit Comments"
End Sub
Private Sub MyLogSQL()
Dim mySQL As String
mySQL = "UPDATE Log SET AuditReason = '" & AudRsn & "' , AuditComments = '" & [Forms]![Audit Comments]![txtAuditNotes].Value & "' WHERE " _
& "UniqueID = " & [Forms]![RTS Audit]![RTS AuditSubform]![UniqueID] & " ;"
DoCmd.RunSQL mySQL
MsgBox "Log file has been Updated."
mySQL = vbNullString
End Sub

orange
05-27-2008, 08:51 PM
Try this:

http://articles.techrepublic.com.com/5100-10878_11-1030273.html

FrymanTCU
06-02-2008, 03:11 PM
Orange, Thanks I like that article but a friend at work pointed me to this article instead: http://www.developerfusion.co.uk/show/113/

It seems simple enough but I keep getting a darn run time error '2465' Application-defined or object-defined error. This is really my first time to set a property or pass a variable.

I am tired of messing with it so I though I'd post the error up here and let one of the braniacs on here solve it.

Thanks, Rich

Form 1 - [RTS Audit]
Public Sub cmdAccptInError_DblClick(Cancel As Integer)
With [Forms]![AuditComments]
'Error is the next line
[Forms]![AuditComments].PassAudRsn = "Accepted in Error"
'.show
End With
'AudRsn = "Accepted in Error"
DoCmd.OpenForm "Audit Comments"
End Sub

Form 2 - [AuditComments]
Option Compare Database
Option Explicit
Public AudRsn As String

Private Sub cmdOKmemo_Click()
Dim myComments As String
myComments = " & Me.txtAuditNotes.Text & "
Call MyLogSQL
DoCmd.Close acForm, "Audit Comments"
End Sub

Public Property Get PassAudRsn() As String
PassAudRsn = AudRsn
End Property

Public Property Let PassAudRsn(ByVal vNewAudRsn As String)
If istext(vNewAudRsn) Then AudRsn = vNewAudRsn
End Property

Private Sub MyLogSQL()
Dim mySQL As String
mySQL = "UPDATE Log SET AuditReason = '" & AudRsn & "' , AuditComments = '" & [Forms]![Audit Comments]![txtAuditNotes].Value & "' WHERE " _
& "UniqueID = " & [Forms]![RTS Audit]![RTS AuditSubform]![UniqueID] & " ;"
DoCmd.RunSQL mySQL
MsgBox "Log file has been Updated."
mySQL = vbNullString
End Sub