We help IT Professionals succeed at work.
Get Started

using variable or a variable string in a Msgbox

Karen Schaefer
on
118 Views
Last Modified: 2016-02-11
Need help with syntax.

I would like to display the cityname, state (if applicable), & country name within the message in the message box.  these values come from the form CountryRecid, combo. column(1) and StateRecid.column(1) and the city name which is txtbox.

Private Sub cmdAdd_Click()
'Dim gCountryID As Integer
'Dim gStateID As Integer
'Dim gCityName As String
Dim n As Integer
Dim nName As String
   On Error GoTo cmdAdd_Click_Error

gCountryID = Nz([Forms]![frmAddLocation]![CountryRecID])
gStateID = Nz([Forms]![frmAddLocation]![StateRecID])
gCityName = Nz([Forms]![frmAddLocation]![CityName])
    
    n = DCount("*", "tblCity", "[CityName] Like '*" & gCityName & "*' " & _
        "AND [CountryRecID] = " & gCountryID & " " & _
        "AND [StateRecID] = " & gStateID & "")

        If n = 0 Then
            DoCmd.RunSQL _
                ("INSERT INTO tblCity ( CountryRecID, StateRecID, CityName, TaxInclusive, Top5000, DateCreated, Modifiedby ) " _
                & "VALUES ( '" & gCountryID & "', '" & gStateID & "', '" & _
                gCityName & "', " & gTaxIncl & ", " & gTop & ", Date(), '" & _
                GetgUserID() & "' )")
        Else
[b]'        nName = gCityName & ", " & [Forms]![frmAddLocation]![StateRecID].Column(1) & ", " & [Forms]![frmAddLocation]![CountryRecID].Column(1)
'       Debug.Print nName
            Select Case MsgBox("Records Found & ", "  & gCityName &   , vbYesNo Or vbExclamation Or vbDefaultButton1, ")[/b]

                Case vbYes

                Case vbNo

            End Select

        End If

   On Error GoTo 0
   Exit Sub

cmdAdd_Click_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdAdd_Click of VBA Document Form_frmAddLocation"

End Sub

Open in new window

Comment
Watch Question
Owner, Dev-Soln LLC
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2010
Commented:
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE