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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntax error 1

Status
Not open for further replies.

vttech

Technical User
Jan 28, 2006
297
US
I keep getting a syntax error on the code below.. Why?



Code:
Private Sub cmdSubmit_Click()

if (me!cboWorkDate.value = "" or me!txtLogIn.value = "" or
me!txtLogOut.value = "" or me!cboSite.value = "" or me!cboActivity.value = "") then
MsgBox NameOfField & " is a required field"
Else
InputLogInOut
End If

End Sub

Newbie in search of knowledge
 
Is this defined somewhere else?
Code:
InputLogInOut
 
But, your sytnax error is here:
Code:
if (me!cboWorkDate.value = "" or me!txtLogIn.value = "" or
me!txtLogOut.value = "" or me!cboSite.value = "" or me!cboActivity.value = "") then
MsgBox NameOfField & " is a required field"
Else
InputLogInOut
End If

Change to:
Code:
if (me!cboWorkDate.value = "" or me!txtLogIn.value = "" or [highlight]_[/highlight]
me!txtLogOut.value = "" or me!cboSite.value = "" or me!cboActivity.value = "") then
MsgBox NameOfField & " is a required field"
Else
InputLogInOut
End If

Assuming this is exactly how you have it in your code.
 
OK I see what you mean since the code spans several lines I need a _ to connect lines

Newbie in search of knowledge
 
dim FieldsRequired as string

I want to create a sub that checks the combo/text boxes on my form for values = ""
if so they would and that combo/text boxes name to FieldsRequired

Example:

Me!cboWorkDate.Value = ""
Me!txtLogin.Value = ""
Me!cboSite.Value = ""

then FieldsRequired would equal cboWorkDate.Name, txtLogin.Name, cboSite.Name

How would I go about creating this with VBA code??


Newbie in search of knowledge
 
Well, for the "" part, I would just use:

Code:
If IsNull(cboWorkDate) Then
   ~do whatever
End If

Or for setting a value to Null, you could use:
Code:
Private Sub Whatever()
  Other stuff
  
  Me!cboWorkDate = vbNullString
  Me!txtLogin = vbNullString
  Me!cboSite = vbNullString

  Other stuff

End Sub
[/code
 
Well, for the "" part, I would just use:

Code:
If IsNull(cboWorkDate) Then
   ~do whatever
End If

Or for setting a value to Null, you could use:
Code:
Private Sub Whatever()
  Other stuff
  
  Me!cboWorkDate = vbNullString
  Me!txtLogin = vbNullString
  Me!cboSite = vbNullString

  Other stuff

End Sub
 
I had a bad feeling about that - Internet Explorer messed up on me, and I ended up sending it twice (they are the same, except the formatting is 100% correct in second instance). - my posts.
 
So I would have to use an if statement to check to see if that field is Null and then add that name to RequiredField list… Seems like a lot of typing but if that’s the only way to gather the names of the text and combo boxes that are null.

Code:
dim RequiredField as string

If IsNull(cboWorkDate) Then
   RequiredField = cboWorkDate.Name &", "
End If

If IsNull(txtLogin) Then
   RequiredField = txtLogin.Name &", "
End If

If IsNull(cboSite) Then
   RequiredField = cboSite.Name &", "
End If




Newbie in search of knowledge
 
I would think that would be the best method. But, if you are checking all of your controls, you might could use a loop, moving through the controls - might be a little less typing:

Code:
Private Sub CheckForNulls()
  Dim ctl as Control
  For Each ctl in Form.Controls
    If TypeOf ctl Is ComboBox or TypeOf ctl Is TextBox _
    or TypeOf ctl Is ListBox Then
       If IsNull(ctl) Then
         'your code here for dealing with these
       Else
         'your code if any for dealing with non-null controls
       End If
    End If
[/code]
 
First of all there is a big difference between a null value and a null string, the two are not the same. A variant can be null a string can have a null string "". This is a better check

if trim(me.controlname & " ") = "" then

This handles a null value, a null string, an empty value, and spaces " ".
Second you could put "required" in the tag properties of the control
Code:
'untested
private function strRequired() as string 
  dim cntrl as access.control
  dim lenStrRequired as integer
  for each cntrl in me.controls
    if cntrl.tag = "required" then
       strRequired = strRequired & cntrl.name & ","
    end if
  next cntrl
  lenStrRequired = len(strRequired)
  if lenStrRequired>0 then
  strRequired = left(strRequired,lenStrRequired - 1)
end function
 
Another note you'll want to look at later:

In your form searchBOOKINGS, the procedure, Private Sub Search_Change() has a line, vSearchString = Search.Text.

That line is giving a compile error: method or data member not found..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top