Full Version: VBA Button
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
Super_Momak
I have a button on one form that does the following:

Private Sub cmdRankChange_Click()
On Error GoTo Error_Change

Dim indicator As VbMsgBoxResult

indicator = MsgBox("Are you sure this soldier's rank should be changed?", vbYesNo, "Promotion")

If indicator = vbNo Then
Exit Sub
End If

Dim The_SQL As String
Dim The_Date As Date

The_Date = Date

The_SQL = "INSERT INTO tblRankChange ( SoldierCode, OriginalRank, DateOriginated, DateFinalized ) " & _
"SELECT " & Me![SoldierCode] & ", " & Me![RankCode] & ", Date(), Date()"

Dim The_Form As String
Dim The_Filter As String

The_Form = "frmRankChange"
The_Filter = "[SoldierCode]=" & Me![SoldierCode] & " And [DateOriginated]='" & Date & "' And [OriginalRank]=" & Me![RankCode]

MsgBox The_Filter

DoCmd.RunSQL The_SQL

MsgBox The_Filter

DoCmd.OpenForm The_Form, , , The_Filter

Exit_Change:
Exit Sub

Error_Change:
MsgBox Err.Description
Resume Exit_Change

End Sub


The form frmRankChange open fines if I hide the SQL, but if the SQL is visible, a message pops up saying the OpenForm Action was Canceled or something like that. How do I set it up where both run just fine. I want to only open the form for one particular record, so I created pretty strict criteria when it opens. The record I am "looking for" was just generated by the SQL that is run prior to the form being opened. The long and short of it: I need to generate a new record in my tblRankChange table, and be able to open a form with the information in the new record I just created, so it can be properly input. Any assistance would be extremely helpful.
EFCoins
what do you mean by
"if the SQL is visible"
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.