Compile error: Variables not defined

klwu

Brainy!!
Local time
Tomorrow, 06:32
Joined
Sep 13, 2004
Messages
47
Hi, I have some problems with my codes here. The system keeps saying that my variables not defined. How do I solve this problem? Thanks

Code:
Private Sub cmdCreateNew_Click()
On Error GoTo Err_cmdCreateNew_Click
'1.Check if cmbCompanyID is selected
'2.Generate a unique numer for this Company ID
'3.Insert a row in M_Ip table
'4.Go to IPAddress form

Dim sSql As String, refIx As Long, dbs As Database

'task 1 begins here--------
If IsNull(cmbCompanyID) Or cmbCompanyID = "" Then
    MsgBox "Please select the Company ID"
    GoTo Exit_cmdCreateNew_Click
End If

'task 2 begins here--------
refIx = NextVal(cmbCompanyID)
        
   
'task 3 begins here-------
sSql = "INSERT INTO M_Ip (RefNo, CompanyID) VALUES" & _
       "(" & refIx & ", '" & [B]txtCompanyID [/B] & "');" [COLOR=Red]<- Error here[/COLOR]

'task 4 begins here------
    DoCmd.OpenForm "IPAddress", acNormal, , "RefNo =" & refIx
    DoCmd.SetWarnings True
    cmbCompanyID = ""
    
'MsgBox sSql
    DoCmd.SetWarnings False
    DoCmd.RunSQL sSql

   
Exit_cmdCreateNew_Click:
    Exit Sub

Err_cmdCreateNew_Click:
    MsgBox Err.Description
    Resume Exit_cmdCreateNew_Click
    
End Sub
 
Sorry, I think I didn't actually explain my problem.

I have 2 forms: AddIP and IPAddress. I have a combo box in
AddIP form, I want to do like when the user selects a Company ID in this
form and after the button 'Create New' is clicked, the IPAddress form will
appear with a new Ref. No. (from T_Counter table) and the Company ID field is populated with the ID (from R_CompanyID table). The code I wrote is meant for the "Create New" button.

Could someone advise me on this?
 
klwu,

When I took the " <- Error here" away from the end of the line, there is
no compile error.

It compiles fine in A2000.

Wayne
 

Users who are viewing this thread

Back
Top Bottom