Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Statement invalid outside of type block 1

Status
Not open for further replies.

bodmin

Technical User
Apr 1, 2004
98
GB
Hi,

Im trying to use the following code to check if the relevant field on a form has been completed before updating the subform. If the field has no value then it should display a message box asking the user to return to the form and provide one. Though when I attempt to use the procedure it gives me the runtime error that the statement is invalid outside of type block. Im not sure how to fix this, someone please helllpppp

Private Sub DebitUpdate_Click()
On Error GoTo Err_DebitUpdate_Click

Dim DebitAcc As String
Dim DebitAmnt As Currency
Dim DebitDescr As String

Dim Analysis0 As String
Dim Analysis1 As String
Dim Analysis2 As String
Dim Analysis3 As String
Dim Analysis4 As String
Dim Analysis5 As String
Dim Analysis6 As String
Dim Analysis7 As String
Dim Analysis8 As String
Dim Analysis9 As String
Dim T0 As String
Dim T1 As String
Dim T2 As String
Dim T3 As String
Dim T4 As String
Dim T5 As String
Dim T6 As String
Dim T7 As String
Dim T8 As String
Dim T9 As String
Dim localConnection As ADODB.Connection
Dim strSql As String
Dim rs As ADODB.Recordset
Dim Message As String

T0 = "T0"
T1 = "T1"
T2 = "T2"
T3 = "T3"
T4 = "T4"
T5 = "T5"
T6 = "T6"
T7 = "T7"
T8 = "T8"
T9 = "T9"



Set localConnection = CurrentProject.AccessConnection
localConnection.CursorLocation = adUseClient

Set rs = New ADODB.Recordset

DebitAcc = Forms!Main!DebitAccount

If IsNull(DebitAcc) Then
Message = "A Debit Account number has not been selected please return to the form and choose an account"
MsgBox(Message, [vbOKOnly], [Missing Account Number]) As VbMsgBoxResult
Resume Exit_DebitUpdate_Click
End If

Thanks
Andi
 
Hi Andi,

you are trying to declare a variable instead of displaying your message;

Code:
MsgBox(Message, [vbOKOnly], [Missing Account Number]) As VbMsgBoxResult

the As VbMsgBoxResults is used when you Dim a variable. To actually display the message you need to use;

Code:
Display = MsgBox(Message, [vbOKOnly], [Missing Account Number])

optionally with the corresponding dim statement;

Code:
Dim Display as VbMsgBoxResult

Hope that helps
Sim

----------------------------------------
I was once asked if I was ignorant or just apathetic. I said, "I don't know, and I don't care."
----------------------------------------
 
Furthermore, If IsNull(DebitAcc) will NEVER be true.
Try this instead:
If IsNull(Forms!Main!DebitAccount)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top